powershell - 如何在PowerShell中使用CSOM连接到内部部署SharePoint 2013

标签 powershell sharepoint sharepoint-2013

我知道在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)禁止。“
在C:\ Users \ v-krirao \ Desktop \ test.ps1:17 char:2
+ $ clientContext.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:未指定:(:) [],MethodInvocationException
+ FullyQualifiedErrorId:WebException

最佳答案

虽然您的代码在我的2013网站上对我有用
... Extensions \ 16 \ ISAPI ...不是特定于SP2013的,请尝试以下操作;

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

关于powershell - 如何在PowerShell中使用CSOM连接到内部部署SharePoint 2013,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510867/

相关文章:

powershell - 从PowerShell中的列表中选择一个项目

powershell - powershell复制项路径中的非法字符

c# - 使用 System.Reflection 时验证异常时出错

javascript - SharePoint Online REST - 通过 JavaScript/AJAX 上传图片

javascript - 从文档库中获取文件名

css - 将 CSS 应用于单个 Web 部件上的 Sharepoint 站点

html - 在 Sharepoint 2013 中将嵌入的 SWF 对齐到中心

sql-server - 远程Powershell访问被拒绝

azure - 备份 Azure 数据库时如何备份事务日志?

c# - ASMX 网络服务不返回 JSON,只能使用 application/x-www-form-urlencoded contentType 进行 POST