【发布时间】:2017-09-16 13:50:30
【问题描述】:
我知道使用 PowerShell 中的 CSOM 我们可以从本地计算机连接到 SharePoint Online,我们如何使用 PowerShell 中的 CSOM 连接到本地 SharePoint 2013?
注意:我正在使用 System.Net.NetworkCredential 获取 On-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
以下是错误:
使用“0”参数调用“ExecuteQuery”的异常:“远程服务器返回错误:(403) Forbidden。” 在 C:\Users\v-krirao\Desktop\test.ps1:17 char:2 + $clientContext.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WebException
【问题讨论】:
标签: powershell sharepoint sharepoint-2013