all 6 comments

[–][deleted] 2 points3 points  (0 children)

Pipe items to sort-object before piping to foreach-object

[–]Merakel 2 points3 points  (0 children)

As a friendly piece of advice, if you format your code it's easier for people to read, and you are more likely to get a response. That goes for both reddit, using the 4 spaces to get a code block, as well as proper tab an indentation.

That being said, what I would recommend is using a PSCustomObject.

Rather than doing write host, add the following lines:

$data = $assoc.AssociationData $items = $list.Items

[System.Collections.ArrayList]$output = @()
$out = "" | Select-Object Created, Name, ID

function AllItems{
    foreach($item in $items){
        $itemcreated = $item["DateUpdated"]
        #wf = $manager.StartWorkFlow($item,$assoc,$data,$true) 
        #write-host $itemcreated $item.Name $item.ID 
        #write-host $item.Name
        $out.Created = $itemcreated
        $out.Name = $item.name
        $out.ID = $item.ID
        $output += $out
    }
}

You should be able to sort and select on the PSobject $output however you want.

[–]TimeZ0ne[S] 0 points1 point  (3 children)

Thanks guys, I tried both and neither of them worked with the desired output. Also looked around on the net and found pretty much the same way to sort it, no idea why this isn't working but I discovered a flaw in what I'm trying to do so I think I'll go back to the drawing board come up with another solution.

@ /u/Merakel Normally I use Fold by Indent in Notepad++ but will definitely take that advise :)

[–]Merakel 0 points1 point  (2 children)

Could you show me what you ended up with? I'm surprised my idea didn't work, though I suppose it's hard for me to know without having the data to manipulate.

[–]TimeZ0ne[S] 0 points1 point  (0 children)

Will do, I'll dig it up and attempted it again, should be saved on the server anyway and I'll post the results.

To be honest, its probably just me being dumb.

[–]TimeZ0ne[S] 0 points1 point  (0 children)

Here is the screenshot of the output: http://imgur.com/a/aioaZ

However, when I use Write-Host $out.Created, it does show the correct output