【问题标题】:The remote server returned an error: (400) Bad Request Visual Code远程服务器返回错误:(400) Bad Request Visual Code
【发布时间】: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


【解决方案1】:

如果安装了最新的 SharePoint Online,请检查此文件夹中是否有 dll:

然后在 Visual Studio 中安装 PowerShell 插件:

那么它应该能够按预期运行,这是我这边的结果:

【讨论】:

  • 我已经做了上面提到的所有事情,但仍然是同样的错误。可能是我缺少一些配置。天知道为什么? :(
  • 你能在 PowerShell ISE 中运行脚本吗?就我而言,Visual Studio Code 只需要安装 PowerShell 插件并将代码保存为 ps1 文件,然后就可以运行和调试了。
  • 卸载可视代码,重新启动机器并再次安装对我有用。
猜你喜欢
  • 2010-12-13
  • 1970-01-01
  • 2013-04-20
  • 2012-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多