【发布时间】:2020-06-24 03:31:54
【问题描述】:
我正在尝试借助 Visual Code 连接到我的 Sharepoint Online 网站集,但出现以下错误 - 远程服务器返回错误:(400) 错误请求。 代码-
Add-Type -Path "C:\dlls\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\dlls\Microsoft.SharePoint.Client.Runtime.dll"
$userName = "***"
$password = ConvertTo-SecureString "" -AsPlainText -Force
$webURL="https://test.sharepoint.com/sites/test/"
$Context=New-Object Microsoft.SharePoint.Client.ClientContext($webURL)
$Context.Credentials=New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$password)
$Web=$context.Web
$Context.Load($web)
$Context.executeQuery()
Write-host $Web.URL
【问题讨论】:
-
您的代码很好,我可以在安装了 powershell 扩展的 Windows powershell 和 VS Code 中运行它。但是,您可以尝试下载 SharePoint Online 客户端组件并引用已安装的 dll
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" -
我已经安装了最新的 dll 但仍然是同样的问题 :(。我也启用了 powershell ISE 模式。
-
你在 powershell 中测试过这个吗?
-
是的,它正在 Powershell ISE 上运行。
-
尝试再次在 VS 代码中卸载并安装 powershell 扩展
标签: powershell sharepoint sharepoint-online csom