Search This Blog

Monday, December 8, 2014

Export List Items in SharePoint using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 
  
#Get the target site collection 
$web = Get-SPWeb -identity "http://sp2010.contoso.com/finance/"
  
#Get the Target List 
$list = $web.Lists["Purchase"] 
  
#Array to Hold Result - PSObjects 
$ListItemCollection = @() 
  
 #Get All List items where Products is Stationary
 $list.Items |  Where-Object { $_["Products"] -eq "Stationary"} | foreach { 
 $ExportItem = New-Object PSObject  
 $ExportItem | Add-Member -MemberType NoteProperty -name "Products" -value $_["Products"] 
 $ExportItem | Add-Member -MemberType NoteProperty -Name "Quantity" -value $_["Quantity"] 
 $ExportItem | Add-Member -MemberType NoteProperty -name "Vendor" -value $_["Vendor"] 
 $ExportItem | Add-Member -MemberType NoteProperty -name "ID #" -value $_["ID"]
 $ExportItem | Add-Member -MemberType NoteProperty -name "Department" -value $_["Department"]

  
 #Add the object with property to an Array 
 $ListItemCollection += $ExportItem
 } 
 #Export the result Array to CSV file 
 $ListItemCollection | Export-CSV "\\sp2010\C$\Scripts\temp\export.csv" -NoTypeInformation                        

#Dispose the web Object 
$web.Dispose()

No comments:

Post a Comment