Using PowerShell to extract SharePoint ListItems and Export into CSV

92 Views Asked by At

I have been trying to export SharePoint List Items in CSV file after applying Group By & Sorting as provided in below PowerShell Script.

$dt=$ListItems.GetDataTable()
$go=$dt | Group-Object "ProjectName"
$ad=$go | Sort-Object -Property {$_.Values[0]},{$_.Count} -Descending
$ad | Select-Object -Property {$_.Values[0]},{$_.Count} | Export-CSV "D:\ProjectInfo.csv" -NoTypeInformation

The above code generating an CSV file where "ProjectName & Count" field in output CSV is not in Descending Order as mentioned below.

ProjectName-Count
-----------------
Project10-12 
Project11-8 
Project12-5 
Project13-13

Instead, output CSV file should generate "ProjectName & Count" field as shown below

ProjectName-Count
-----------------
Project13-13 
Project10-12 
Project1-8 
Project12-5

Please help me how to export CSV file with an Descending order

0

There are 0 best solutions below