2017-07-18 202 views
1

我开发了一个脚本来检索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凭证的用户),并在服务器上,我使用的是本地用户。

任何想法或提示?

回答

1

经过一番调查,我终于找到了问题。 我正在测试脚本的服务器未加入域。因此,服务器和SP在线之间不存在可信任,导致认证失败 - 尽管没有任何指示。 检查$error[0]|format-list -force是驱使我测试身份验证问题的原因。

尝试在不同的其他客户端和域加入的服务器上的脚本已成功。

尽管没有更多的要求,但我找不到能够在工作组服务器上运行脚本的方法,如果没有联合身份验证,SharePointOnlineCredentials似乎无法处理登录...但纠正我如果我错了