PowerShell Script to export SharePoint List in Excel File

In this blog, I will write about "Export SharePoint list items using PowerShell Script".

Prerequisite to execute below PowerShell script.

Create a folder with name  "Test" in drive C:
Create a SharePoint List with name "EmpList"
EmpList should contains 4 columns
ID, Title, EmpName, Department

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 Items in Excel 

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:\Test\MyList.csv"                   
#Dispose the web Object

You may read some popular blogs on SharePointCafe.Net



SharePoint Interview Questions and Answers

Calling ASP.Net WebMethod using jQuery AJAX

What is Cloud Computing - A guide for beginners

How to Crop and Upload image using JQuery