Answered by:
<<How to export a list using powershell?>>

Question
-
Hi,
Add-PSSnapin "Microsoft.SharePoint.PowerShell" $MyWeb = Get-SPWeb "http://webapp/site" $MyList = $MyWeb.Lists["Test"] $exportlist = @() $Mylist.Items | foreach { $obj = New-Object PSObject -Property @{ “Name” = $_["Title"] "Column 1" = $_["Column 1"] "Total" = $_["Total"] "Grand Total" = $_["Grand Total"] } $exportlist += $obj $exportlist | Export-Csv -path 'C:\Users\username\Desktop\export.csv' }
How can I display the columns as
Title, Column 1, Total and Grand Total
in the export file?
Thanks.
Answers
-
depending on the PowerShell version you are running you can either:
Change: New-Object PSObject -Property @{
to: [pscustomobject][ordered]@{or if that doesn't work (needs powershell 4 or better I believe)
Change: } | Export-Csv -path 'C:\Users\username\Desktop\export.csv' -NoTypeInformation
to: Change: }| select title, 'column 1', total, 'grand total' | Export-Csv -path 'C:\Users\username\Desktop\export.csv' -NoTypeInformation
- Marked as answer by Andy__G Thursday, April 6, 2017 8:30 PM
-
try this
$MyWeb = WebUrl $MyList = MyWeb.Lists["ListName"] $MyItems = $MyList.Items $MyItems | Select Fields.. | Export-Csv FilePath $MyWeb.Dispose()
Sources:
- Export SharePoint List to Excel using PowerShell.
- Export sharepoint list items to csv using powershell
Thanks, Amit Kumar, LinkedIn Profile ** My Blog
- Marked as answer by Andy__G Wednesday, May 10, 2017 4:40 PM
All replies
-
you just need to change the name in the created object to have the correct header in the CSV - something like this should work
Add-PSSnapin "Microsoft.SharePoint.PowerShell" $MyWeb = Get-SPWeb "http://webapp/site" $MyList = $MyWeb.Lists["Test"] $Mylist.Items | foreach { New-Object PSObject -Property @{ “Title” = $_["Title"] "Column 1" = $_["Column 1"] "Total" = $_["Total"] "Grand Total" = $_["Grand Total"] } } | Export-Csv -path 'C:\Users\username\Desktop\export.csv' -NoTypeInformation
-
-
depending on the PowerShell version you are running you can either:
Change: New-Object PSObject -Property @{
to: [pscustomobject][ordered]@{or if that doesn't work (needs powershell 4 or better I believe)
Change: } | Export-Csv -path 'C:\Users\username\Desktop\export.csv' -NoTypeInformation
to: Change: }| select title, 'column 1', total, 'grand total' | Export-Csv -path 'C:\Users\username\Desktop\export.csv' -NoTypeInformation
- Marked as answer by Andy__G Thursday, April 6, 2017 8:30 PM
-
try this
$MyWeb = WebUrl $MyList = MyWeb.Lists["ListName"] $MyItems = $MyList.Items $MyItems | Select Fields.. | Export-Csv FilePath $MyWeb.Dispose()
Sources:
- Export SharePoint List to Excel using PowerShell.
- Export sharepoint list items to csv using powershell
Thanks, Amit Kumar, LinkedIn Profile ** My Blog
- Marked as answer by Andy__G Wednesday, May 10, 2017 4:40 PM