我开发了一个脚本来检索SharePoint Online服务器上的列表项,该服务器在我的Windows 10笔记本上运行得非常好,但在默认的Windows Server 2012 R2实例上运行得并不错。下面是相关代码:Powershell连接到SharePointOnline
$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
变量没有得到任何列表从SharePoint回2K12 R2服务器上,因此我得到以下错误到底。
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 Management Shell,Powershell版本相同,并加载了DLL(请参阅下文)。代理设置在两个系统上都是相同的。通过浏览器,我可以访问服务器上的SharePoint Online。
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
唯一的区别就是我登录在我的笔记本上的域用户(虽然不是来自同一个域中使用SP凭证的用户),并在服务器上,我使用的是本地用户。
任何想法或提示?