Powershell export SharePoint 2010 list to a csv file RRS feed

  • General discussion

  • I am running SharePoint Server 2010 in a Windows 8 R2 environment

    In the same server in a folder with the proper permissions I have the following power shell script 

    $MyWeb = Get-SPWeb ""
    $MyList = $MyWeb.Lists["TimeOffHHRR"]
    $exportlist = @()
    $Mylist.Items | foreach {
    $obj = New-Object PSObject -Property @{
                "Full_Name" = $_["Title"]
               "ID_Original" = $_["ID Original"]                  
    $exportlist += $obj 
    $exportlist | Export-Csv -path 'S:\Temp\Danilo\Process.csv'

    When I run the script the CMD window shows the following:

    Script output

    I tried with different column names and the error always show up in the same line / position.

    Your help will be greatly appreciated.



    Thursday, January 4, 2018 9:24 PM

All replies

  • I don't understand why everyone thinks you have to create an empty array and continuously append objects to it, then export it. You can do this all at once. Example (not tested):

    $MyWeb = Get-SPWeb ""
    $MyWeb.Lists["TimeOffHHRR"].Items | ForEach-Object {
      New-Object PSObject -Property @{
        "Full_Name" = $_.Title
        "ID_Original" = $_."ID Original"
    } | Export-Csv "S:\Temp\Danilo\Process.csv" -NoTypeInformation

    -- Bill Stewart [Bill_Stewart]

    Thursday, January 4, 2018 9:33 PM
  • Hello Bill,

    Thanks for your reply. The script works and only produce a CSV file with the headers as shown in the next screenshot.

    I need to add all items from the list. Could you please tell me what is missing in the script to make it export the entire list?


    Excel output


    Friday, January 5, 2018 3:08 PM
  • I don't know because I don't use SharePoint, nor do I have access to your SharePoint site. I was assuming your original code iterates the content correctly. If that's not the case, I can't help any further unfortunately.

    -- Bill Stewart [Bill_Stewart]

    Friday, January 5, 2018 3:48 PM