Thursday, 30 August 2012

Export SharePoint List data into CSV file


I have found couple of blogs explaning the reverse way of expoting csv file data into SharePoint list. I have accomplished the other way around and hence thought of sharing this with you.

InOrder to export data from SharePoint list into CSV file, lets first query SharePoint list and get the required items and then we will export these items into CSV file.

$spSiteUrl = "http://sharepointwebapplication"
$listtitle="My Custom List"
$spWeb= Get-SPWeb -Identity $spSiteUrl
Function ImportDataFromListToCSV
  IF($spWeb -ne $null)
  $list = $spWeb.Lists.TryGetList($listtitle)
  $exportlist = @()
  $items = $list.Items
  Write-Host "Exporting........" -ForegroundColor Yellow
  if($items -ne $null)
    #Here "givenName" column name for CSV file and "Given Name" column name SharePoint List
    $items | %{ select-object -input $_ -prop @{Name='givenName';expression={$_["Given     Name"];}},@{Name='surname';expression={$_["Family Name"];}};}| Export-Csv -Path C:\Demo.csv -NoTypeInformation
    Write-Host "SharePoint list data is exported successfully." -ForegroundColor Green
 {Write-Host "No data found in the list "$listtitle -ForegroundColor Yellow}}

Enjoy PowerShell,
Isha Jain

1 comment:

  1. Reading your article is such a privilege. It does inspire me, I hope that you can share more positive thoughts. Visit my site too. The link is posted below.