【发布时间】:2018-04-06 18:21:05
【问题描述】:
在网上看,我想出了这 2 个函数来使用这 3 个带有 powershell 的 DLL 请求 Sharepoint:
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 有什么区别?
【问题讨论】:
-
AFAIK,有延迟加载的属性。也许您必须使用它的 ID 来请求自己的价值?
-
不确定它是否属于 SharePoint Stack,因为它是用 PowerShell 编写的。我如何使用 ID 请求他们?仅供参考,ID 是他所在列表中项目的位置。 OtherField 是 13 个元素的列表,因此 ID 介于 1 和 13 之间。
-
PowerShell 是一种众所周知的 SharePoint 管理工具,而不仅仅是一种编程语言 ;) 问问自己:如果用任何其他语言编写,它会有什么不同吗?但是,是的,它与 SO 并非完全无关;)我不知道。如果我愿意,我已经发布了答案
-
我想我可能已经发现了问题:FieldChoice 是由同一站点上的另一个列表组成的。并且我正在使用的用户不允许访问此列表。这就是为什么我无法请求价值但我仍然获得 ID 的原因。我正在申请权利,然后我会发布解决方案。
标签: powershell sharepoint csom