Visual Studio Code Powershell 启动失败

4

我在 Windows Server 2012 R2 上使用版本为 1.49.0 的 VSCode 用户安装版,用于 PowerShell 开发。在我的 Windows 10 笔记本电脑上没有这个问题,但在服务器上需要进行开发工作,因为我编写代码针对的是 SharePoint 2013 的本地对象模型。

我已经安装了 Windows8.1-KB3118401 补丁,但启动控制台时出现以下错误:

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', 'Import-Module 'c:\Users\first.last.vscode\extensions\ms-vscode.powershell-2020.6.0\modules\PowerShellEditorServices\PowerShellEditorServices.psd1'; Start-EditorServices -HostName 'Visual Studio Code Host' -HostProfileId 'Microsoft.VSCode' -HostVersion '2020.6.0' -AdditionalModules @('PowerShellEditorServices.VSCode') -BundledModulesPath 'c:\Users\first.last.vscode\extensions\ms-vscode.powershell-2020.6.0\modules' -EnableConsoleRepl -StartupBanner "=====> PowerShell Integrated Console v2020.6.0 <===== " -LogLevel 'Normal' -LogPath 'c:\Users\first.last.vscode\extensions\ms-vscode.powershell-2020.6.0\logs\1599836315-05dc7ac0-e011-4b28-8568-c8782ebeabc01599836314391\EditorServices.log' -SessionDetailsPath 'c:\Users\first.last.vscode\extensions\ms-vscode.powershell-2020.6.0\sessions\PSES-VSCode-8808-389325' -FeatureFlags @() ...

当我尝试运行一个 hello world 测试脚本时,出现以下错误:

在 PowerShell 会话启动之前,请勿调试或运行 PowerShell 脚本。请等待 PowerShell 会话启动完成,然后再次尝试。

来源:PowerShell Preview (Extension)

看起来似乎与微软的 Powershell 2020.6.0 扩展有关,因为只要启用它就会抛出错误。

有什么方法可以让我的 Powershell 工作正常吗?

2个回答

5
尝试在您的用户设置(JSON)中添加以下内容。
{
  "powershell.integratedConsole.suppressStartupBanner": true,
}

显然,带有-StartupBanner参数执行的Start-EditorServices命令包含一个字符(<),似乎引发了错误。

上述设置指示抑制启动横幅,这解决了此错误。我花了很多时间在互联网上搜寻,最终才得出这个发现。希望Powershell Core团队中的某个人能够修复这个问题。


1
以下是我的解决方法: 前往路径并编辑 > "C:\Users\Name.vscode\argv.json" 添加以下行 > "powershell.integratedConsole.suppressStar谢谢。 - Jeetcu
我尝试了这个,效果非常好。谢谢。 - Sachin
这对我没有帮助。ms-vscode.powershell v2023.6.0 VS Code版本:1.80.0-insider(用户设置)提交:61ba389b0a7108af0411c73ab30c7e4350051645日期:2023-06-16T09:46:56.229Z Electron:22.5.7 Chromium:108.0.5359.215 Node.js:16.17.1 V8:10.8.168.25-electron.0 操作系统:Windows_NT x64 10.0.19044 - Mavaddat Javid

1
我遇到了这个错误,因为我正在使用PowerShell 4(任何低于5的版本显然都有这个问题)。

您可以使用以下命令找出您正在使用的PS版本: Get-Host | Select-Object Version

这里有一个安装旧版PowerShell扩展的指南: https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/vscode/using-vscode?view=powershell-7.1#using-an-older-version-of-the-powershell-extension-for-windows-powershell-v3-and-v4

但简要说来:

  1. 右键单击PowerShell扩展并选择“安装其他版本...”
  2. 选择版本“2020.1.0”。

它还建议禁用自动更新。 X


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接