Hi,
I’m trying to Sort-Object on the results of a ForEach loop and it doesn’t seems to be working as expected. The source of the data is from a column in a SharePoint list and i’m trying to sort the dates in a ascending order.
CODE:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction silentlycontinue $web = Get-SPWeb "" $manager = $web.Site.WorkFlowManager $list = $web.Lists["WorkflowTest"] $assoc = $list.WorkflowAssociations.GetAssociationByName("Workflow","en-US") $data = $assoc.AssociationData $items = $list.Items 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 } } $manager.Dispose() $web.Dispose()
OUTPUT:
14/07/2016 00:00:00 1 1 05/07/2016 00:00:00 1 2 15/06/2016 00:00:00 2 3 18/08/2016 00:00:00 1 4 03/05/2016 00:00:00 1 5 15/09/2016 00:00:00 3 6 15/07/2016 00:00:00 6 7 04/07/2016 00:00:00 7 8 20/06/2016 00:00:00 4 9 11/06/2016 00:00:00 5 10 17/08/2016 00:00:00 6 11 07/09/2016 00:00:00 7 12 04/05/2016 00:00:00 10 13 12/08/2016 00:00:00 9 14 15/09/2016 00:00:00 8 15 19/07/2016 00:00:00 5 16 01/04/2016 00:00:00 11 17 04/09/2016 00:00:00 15 18 03/05/2016 00:00:00 16 19 03/07/2016 00:00:00 13 20 26/07/2016 00:00:00 14 21 16/07/2016 00:00:00 11 22 01/07/2016 00:00:00 13 23 27/04/2016 00:00:00 14 24 08/08/2016 00:00:00 15 25 23/07/2016 00:00:00 16 26
the results are shown ascending by column ID, is there a way to sort by date so that the earliest date is at the top and latest date at the bottom?
thanks
submitted by /u/TimeZ0ne
[link] [comments]
The post Sort-Object on ForEach Loop appeared first on How to Code .NET.