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
$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



Keep following SharePointCafe.Net for upcoming blogs.


Protected by Copyscape

Comments

  1. PowerShell Script to Export SharePoint List items in excel however your code says csv

    ReplyDelete

Post a Comment

Dear Readers, Please post your valuable feedback in the comment section if you like this blog or if you have any suggestions. I would love to hear the same from you. Thanks

Popular