使用 Power Shell 遍历 SharePoint 列表

Iterate through SharePoint list using Power Shell

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

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

如果您有一个内部部署的 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