【发布时间】:2017-12-23 13:16:33
【问题描述】:
我开发了一个脚本来从 SharePoint Online 服务器中检索列表项,该服务器在我的 Windows 10 笔记本上运行良好,但在默认的 Windows Server 2012 R2 实例上却无法正常运行。以下是相关代码:
$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.RequestTimeout = 360000
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$list = $Context.Web.Lists.GetByTitle($ListTitle)
$qry = new-object Microsoft.SharePoint.Client.CamlQuery
$camlString = "somequery"
$qry.ViewXml = $camlString
$items = $list.GetItems($qry)
$Context.Load($items)
$Context.ExecuteQuery()
不幸的是,$list 变量没有从 2k12 R2 服务器上的 SharePoint 返回任何列表,因此我最终收到以下错误。
Exception calling "ExecuteQuery" with "0" argument(s): "Value cannot be null.
Parameter name: key"
At E:\temp\MDS_SharepointTracker_v2.ps1:131 char:5
+ $Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
我很确定它与身份验证有关,但我无法弄清楚是什么。
两个系统上用于登录的凭据相同,两个系统都安装了 SharePoint Online 命令行管理程序,Powershell 版本相同并且加载了 DLL(见下文)。两个系统上的代理设置相同。通过浏览器,我可以访问服务器上的 SharePoint Online。
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
唯一的区别是我在笔记本上使用域用户登录(尽管与用于 SP 凭据的用户不在同一个域),而在服务器上,我使用的是本地用户。
任何想法或提示?
【问题讨论】:
标签: list powershell authentication sharepoint login