[英]Error Copying the Folder! Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (400) Bad Request."
[英]Exception calling “ExecuteQuery” with “0” argument(s): “The remote server returned an error: (401) Unauthorized.”
如果我运行下面的 PowerShell 脚本,我会收到以下错误:使用“0”参数调用“ExecuteQuery”的异常:“远程服务器返回错误:(401)未经授权。”
我在这个网站和其他网站上阅读了几篇文章,但其中所有文章都已经 3 岁以上,不能解决我的问题。
该脚本运行良好,但从上周二开始,powershell 脚本给出了此异常。 没有改变。 我尝试在不同的计算机上运行脚本,但结果相同。 如果我使用其他用户,错误仍然存在。 SharePoint没有问题报告,我可以通过浏览器登录SharePoint。
我希望你能帮助我。 感谢您的帮助!
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"
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SharePointUri)
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User, $SecurePassword)
$Context.Credentials = $Credentials
#Retrieve list
$List = $Context.Web.Lists.GetByTitle($DocumentLibrary)
$Context.Load($List.RootFolder)
$Context.ExecuteQuery();```
使用 SharePoint PNP 模块解决了问题。 https://github.com/pnp/PnP-PowerShell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.