【发布时间】:2016-10-13 19:19:04
【问题描述】:
在 SharePoint 2013 上,我正在尝试使用客户端 SharePoint PowerShell 获取列表项。 即使对于字段 Id 或 Title,我也会遇到此错误:集合尚未初始化。 我不知道如何包含字段。我在 C# 或 JavaScript 中找到了许多示例,但在客户端 powershell 中没有。
这是我的代码(它正确返回了项目数):
Function New-Context([String]$WebUrl) {
$context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl)
$context.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$context
}
Function Get-List([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
$list = $context.Web.Lists.GetByTitle($ListTitle)
$context.Load($list)
$context.ExecuteQuery()
$list
}
$context = New-Context -WebUrl "http://mysharepoint.com/sites/qp"
$list = Get-List -Context $context -ListTitle "QP-Configuration"
$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
$items = $list.GetItems($query)
$context.Load($items)
$context.ExecuteQuery()
$items.Count
$items[0]
foreach($item in $items)
{
$item.Id
}
$context.Dispose()
【问题讨论】:
-
请发布完整的错误,包括行号等
-
您尝试访问某个项目($items[0] 或在 foreach 中)
format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. + CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand
标签: powershell sharepoint sharepoint-2013 sharepoint-clientobject