使用CSOM據我所知,在PowerShell中使用CSOM我們可以連接到SharePoint Online中從本地機器上,我們如何能夠連接到SharePoint 2013的內部部署在PowerShell中使用CSOM?如何連接到SharePoint 2013的內部部署在PowerShell中
注:我使用System.Net.NetworkCredential獲取用戶名和密碼在-Premsie
用下面的腳本,在執行它得到的錯誤。
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
function OnPremises-Test {
$siteUrl = "https://<>/"
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$clientContext.Credentials = New-Object System.Net.NetworkCredential("myusername", "password")
$web = $clientContext.Web
$clientContext.Load($web)
$clientContext.ExecuteQuery()
Write-Host " Current web title is '$($web.Title)', $($web.Url)"
}
OnPremises-Test
以下是在錯誤:
異常調用 「的executeQuery」 與 「0」 的參數(一個或多個): 「的遠程服務器返回錯誤:禁止(403)」 在C:\用戶\ V-krirao \桌面\ test.ps1:17字符:2 + $ clientContext.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:引發WebException
我有PnP的問題,因爲我必須將腳本切換到其他人將部署的不同環境,無法要求他們安裝PnP cmdlet。 – krishna
我知道你必須將其提交給其他環境。如果可能的話,安裝pnp只需使用一個命令即可完成:「Install-Module SharePointPnPPowerShell2013」,您可以將其作爲腳本的一部分。如果安裝了PNP,請檢查一下。如果沒有,運行給定的命令。 – Vaibhav
我一直默默使用pnp,但經過一些實驗後,我認爲這是一個有用且有據可查的框架。但它本身並不回答OP。 –