【发布时间】:2018-01-03 14:09:46
【问题描述】:
我正在尝试从 powershell 中的共享点在线列表中获取项目(并在第二步中更新它们)。
我在网上尝试了几个例子,但无法弄清楚问题所在。
运行如下代码时:How to get items from a sharepoint online list using PowerShell
$url ="https://company.sharepoint.com/sites/some/site/link"
$username="user@domain.com"
$password="pw"
$Password = $password |ConvertTo-SecureString -AsPlainText -force
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\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
}
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$Context.Credentials = $credentials
$context.RequestTimeOut = 5000 * 60 * 10;
$web = $context.Web
$context.load($web)
$context.ExecuteQuery()
Get-ListItems -Context $context -ListTitle "myListTitle"
我总是收到这个错误:
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
你知道可能出了什么问题吗?
提前致谢 达夫克斯
【问题讨论】:
标签: list powershell sharepoint collections csom