我需要使用特定的网站列获取所有列表的名称。我有以下代码
$web = Get-SPWeb "http://nameofsite/sites/subsite"
$filePath = "E:\lists.txt"
$array = "array of site column names"
foreach ($element in $array)
{
$column = $web.Fields[$element]
$column.ListsFieldUsedIn() | Out- File -FilePath $filePath -Append
}
但它正在做的是将web id和list id发送到文件。有没有办法从$ column.ListsFieldUsedIn()返回id以返回列表的名称?
答案 0 :(得分:0)
您无法从网络实例访问字段属性。
警告!未经测试的代码...
$site = Get-SPSite "http://nameofsite/sites/subsite"
$array = "array of site column names"
foreach($element in $array)
{
$field = $site.RootWeb.AvailableFields[SPBuiltInFieldId.Attachments];
Write-Host "The $($field.Title) Field is used in: "
Write-Host "-->"
$collection = $field.ListsFieldUsedIn()
foreach($usage in $collection)
{
$web = $site.AllWebs[$usage.WebID]
$list = $web.Lists[$usage.ListID]
Write-Host "$($list.Title) list in $($web.Title)"
$web.Dispose()
}
}
$site.Dispose()
有关详细信息,请参阅MSDN example
答案 1 :(得分:0)
我最终这样做了:
$site = Get-SPSite "http://nameofsite/sites/subsite"
$filePath = "E:\lists.txt"
$array = "array of site column names"
$column = $site.RootWeb.AvailableFields[$element]
$lists = $column.ListsFieldUsedIn()
$column.ListsFieldUsedIn() | ForEach-Object {
$w = $site.AllWebs[$_.WebID]
$l = $w.Lists[$_.ListID]
"Web:" +$w.Title+ " List: " + $l.Title+ " ListUrl: " +$l.RootFolder.Url | Out-File -FilePath $filePath -Append
}
根据我在此处找到的代码sharepoint.stackexchange.com