2017-07-18 54 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似乎無法處理登錄...但糾正我如果我錯了