I need to retrieve column names of a list and export to Excel using PowerShell script. Can someone assist me to write a script for this? Thanks in advance.


try with the following code,

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null 
    $site = new-object Microsoft.SharePoint.SPSite("YourSiteURL")
    $web = $site.RootWeb
    $list = $web.Lists["ListName"]
    $view = $list.Views["All Items"] 
    $items = $list.GetItems($view)
    $items | %{ select-object -input $_ -prop @{Name='Title';expression={$_.Title;}}, @{Name='ColumnName1';expression={$_["ColumnName1"];}}; } | Export-Csv -Path c:\test.csv -NoType 
    Remove-PsSnapin Microsoft.SharePoint.PowerShell

In the above script build your select object by giving the required columns names from the SPListItem properties before passing it to Export-CSV.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.