Powershell& Sharepoint导出列表项目通过视图到csv

时间:2011-01-25 17:49:31

标签: powershell sharepoint-2007 wss-3.0

我正在尝试通过特定的视图从共享点列表中导出项目。

我有成功返回的项目,但现在我试图将其正确导出到csv文件

这是我到目前为止:

$web = Get-SPWeb $url
    $splist = $web.Lists[$listname]
    $view = $splist.Views["Current Month"] 
    $items = $splist.GetItems($view)
    $items | Select-Object "Check Number", "Purchaser" | Export-Csv -Path f:\test.csv
    $web.Dispose()

提前谢谢!

1 个答案:

答案 0 :(得分:3)

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

在将选择对象传递给Export-CSV

之前,必须先从SPListItem属性构建选择对象