【问题标题】:Powershell get list items from Sharepoint online using CSOM APIPowershell 使用 CSOM API 从 Sharepoint 在线获取列表项
【发布时间】: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


    【解决方案1】:

    不是 PowerShell 方面的专家,但我认为那行

    Get-ListItems -Context $context -ListTitle "myListTitle"
    

    尝试将调用结果输出到控制台,但由于某些原因,某些 props 未初始化。 尝试将其更改为与文章中的相同:

    $items = Get-ListItems -Context $context -ListTitle "Tasks" 
    foreach($item in $items)
    {
       #...
    }
    

    并在 foreach 循环中将项目道具写入控制台。

    【讨论】:

      猜你喜欢
      • 2014-03-13
      • 2017-11-23
      • 2019-08-03
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 1970-01-01
      相关资源
      最近更新 更多