Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Export SharePoint List Items to CSV using PowerShell

$
0
0
Requirement: Export SharePoint List items to a CSV file.

Export SharePoint list data to CSV using PowerShell:
This script exports SharePoint list to csv using powershell. It retrieves all list items, Filters it based on the provided column value and then creates a property to hold the list item values and then appends the objects which holds the list item values to an array.

Finally, using the Export-CSV Cmdlet, we are exporting the data to CSV file.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$web = Get-SPWeb -identity "http://sharepoint.crescent.com/sites/Operations/"

#Get the Target List
$list = $web.Lists["Monthly Schedule Log"]

#Array to Hold Result - PSObjects
$ListItemCollection = @()

 #Get All List items where Status is "In Progress"
 $list.Items |  Where-Object { $_["Status"] -eq "In Progress"} | foreach {
 $ExportItem = New-Object PSObject 
 $ExportItem | Add-Member -MemberType NoteProperty -name "Title" -value $_["Title"]
 $ExportItem | Add-Member -MemberType NoteProperty -Name "Department" -value $_["Department"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "Status" -value $_["Status"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "Priority" -value $_["Priority"]

 #Add the object with property to an Array
 $ListItemCollection += $ExportItem
 }
 #Export the result Array to CSV file
 $ListItemCollection | Export-CSV "c:\ListData.txt" -NoTypeInformation                        

#Dispose the web Object
$web.Dispose()


Viewing all articles
Browse latest Browse all 1058


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>