我開發了一個腳本來檢索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憑證的用戶),並在服務器上,我使用的是本地用戶。
任何想法或提示?