从 Powershell 中的 Sharepoint 获取 FieldLookupValue

Getting a FieldLookupValue from Sharepoint in Powershell

在网上查看我想出了这两个函数来请求 Sharepoint 使用这 3 个 DLL 和 powershell :

Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Taxonomy.dll
Microsoft.SharePoint.Client.Runtime.dll

此函数用于获取列表中的所有项目

Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
    $list = $Context.Web.Lists.GetByTitle($listTitle)
    $qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
    $items = $list.GetItems($qry)
    $Context.Load($items)
    $Context.ExecuteQuery()
    return $items
}

还有这个工作列表:

Function getChangeListsFromSharepoint(){
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $items = Get-ListItems -Context $context -ListTitle $listName 
    foreach($item in $items)
    {
        /** Working HERE **/
    }
    $context.Dispose()
}

现在,当我使用 Write-Host $item.Fields 显示所有项目内容时,我得到了这样的东西:

[Title,"blabla"]
...
[SpecialField,Microsoft.SharePoint.Client.FieldLookupValue[]]
[OtherField,Microsoft.SharePoint.Client.FieldLookupValue]

我正在尝试获取 SpecialField 和 OtherField 的值。为此,我使用 $item["SpecialField"].LookupValue。我没有问题。但是当我在 OtherField 上执行此操作时,该值为空。如果我尝试使用 $item["OtherField"].LookupID 值不为空并且我有一个 ID。我怎样才能得到这个 ID 背后的价值? FieldLookupValue[]FieldLookupValue 有什么区别?

FieldLookupValue[] 是多值查找列。

它已将 属性 Allow multiple values 设置为 true 并包含一个项目数组。

因此,$item["OtherField"].LookupValue在这里不起作用,您需要按如下方式对其进行迭代:

#multi-value lookup
$mvLookup = [Microsoft.SharePoint.Client.FieldLookupValue[]] $item["OtherField"]        

$mvLookup |% { "Lookup Value: $($_.LookupId):$($_.LookupValue)" }

结果如下:

FieldLookupValue 是单值查找列。它的 Allow multiple values 设置为 false 并包含一个项目。所以,$item["SpecialField"].LookupValue 将在这里工作

所以解决方案很简单:我的用户无权浏览(字段)列表,因为它来自他没有任何权限的(共享点)列表。奇怪的是,在网站上该值是可见的,但在使用 powershell 时却不是。