Powershell & Sharepoint export list items via view to csv
I am attempting to export items from a sharepoint list via a specific View.
I have the items returning successfully but now I am stuck trying to export it to a csv file correctly
here is what i have thus far:
$web = Get-SPWeb $url
$splist = $web.Lists[$listname]
$view = $splis开发者_运维问答t.Views["Current Month"]
$items = $splist.GetItems($view)
$items | Select-Object "Check Number", "Purchaser" | Export-Csv -Path f:\test.csv
$web.Dispose()
Thank you in advance!
For sharepoint 2007
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null
$site = new-object Microsoft.SharePoint.SPSite("http://yoursite")
$web = $site.RootWeb
$list = $web.Lists[$listname]
$view = $list.Views["Current Month"]
$items = $list.GetItems($view)
$items | %{ select-object -input $_ -prop @{Name='Title';expression={$_.Title;}}, @{Name='Check Number';expression={$_["Check Number"];}}; } | Export-Csv -Path c:\test.csv
You have to build your select object up from the SPListItem properties before passing it to Export-CSV
精彩评论