gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:13:20 26 4
gpt4 key购买 nike

我知道在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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com