PowerShell Script to export SharePoint List to Excel or CSV

In this blog, I will write about “How to Export SharePoint list to a excel file?”.
As you know, SharePoint list is a combination of rows and columns. It is similar to a table.

There are multiple ways to export SharePoint list to excel or CSV file, in this blog I will explain about How to export a SharePoint list to Excel or CSV using PowerShell Script? To implement this task follow below steps –

1. Create a folder with the name  “Test” in drive C:
2. Create a SharePoint List with name “EmpList”
3. EmpList should contain 4 columns – ID, Title, EmpName, Department

4. Write below script in a notepad or any editor and save this file as .ps1, .ps1 is the file extension of PowerShell Script.

Change the SharePoint site URL with your running SharePoint site URL and execute the script.

PowerShell Script to Export SharePoint List to Excel or CSV 

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the SPWeb
$web = Get-SPWeb -identity “<sharepoint site url>”
#Get the SPList
$list = $web.Lists[“EmpList”]
$ListItemCollection = @()
 $list.Items | foreach {
 $ExportItem = New-Object PSObject
 $ExportItem | Add-Member -MemberType NoteProperty -name “ID” -value $_[“ID”]
 $ExportItem | Add-Member -MemberType NoteProperty -name “Title” -value $_[“Title”]
 $ExportItem | Add-Member -MemberType NoteProperty -name “EmpName” -value $_[“EmpName”]
 $ExportItem | Add-Member -MemberType NoteProperty -name “Department” -value $_[“Department”]
 $ListItemCollection += $ExportItem
 }
Write-Host “Copying data from list to Excel”
$ListItemCollection | Export-CSV “C:TestMyList.csv”                   
#Dispose the web Object
$web.Dispose()

You may like this – Get data from SharePoint list and store in SQL Table – C# Code

You may read some popular blogs on SharePointCafe.Net

C# 6.0 new features

What is Cloud Computing?

\What is DevOps?

What is Azure Cloud service?

SharePoint Interview Questions and Answers

SharePoint 2013 Server Object Model

Learn CAML Query in SharePoint

What are MicroServices?

Keep following SharePointCafe.Net for upcoming blogs.

1 thought on “PowerShell Script to export SharePoint List to Excel or CSV”

Leave a Comment