使用Power Shell迭代SharePoint列表

时间:2016-09-09 07:24:07

标签: powershell sharepoint sharepoint-2010 powershell-v2.0

我有一个名为" ListA"的SharePoint列表其中包含以下列 身份证,姓名,公司和地址

该列表包含许多记录,我希望根据公司名称获取列表中的所有项目" C"并写下项目名称。如何使用SharePoint Powershell脚本遍历列表?

1 个答案:

答案 0 :(得分:0)

如果您有一个内部部署的SharePoint服务器场,这里有一个简短的代码段,可以帮助您获得所需内容:

# Define the URL of the site collection you will be querying
$siteURL = "http://yourfarm.domain.com/"
# Define the Title of the web that hosts your list
$webTitle = "TheWebTheListIsOn"
# Define the Title of the List that you will be querying
$listTitle = "ListA"

# Create a unique file name for the csv export
$date = Get-Date -UFormat "%Y%m%d"
$csvFilePath = "$($webTitle.Replace(' ',''))_$($listName.Replace(' ',''))_$($date).csv"

# Query the list based on a criteria and export to csv 
$items = Get-SPSite -Identity $siteURL `
    | select -ExpandProperty AllWebs `
    | where { $_.Title -eq $webTitle } `
    | select -ExpandProperty Lists `
    | where { $_.Title -eq $listTitle } `
    | select -ExpandProperty Items `
    | where { $_['Company'] -like "C*" } `
    | select Id, Name, Company, Address `
    | Export-Csv -NoTypeInformation -Path $csvFilePath