Visual Studio Code Powershell startup failure

Viewed 5113

I'm using VSCode version 1.49.0 user setup on Widows Server 2012 R2. I use it for powershell development. I do not have this issue on my windows 10 laptop but do on the server where I need to do my dev work since I write code against the sharepoint 2013 on-premises object model.

I have the Windows8.1-KB3118401 installed WHen starting the console I get the following:

"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 @() ...

when I try to run a hello world test script I get:

Cannot debug or run a Powershell script until the PowerShell session has started. Wait for PowerShell session to finish starting and try again.

Source: PowerShell Preview (Extension)

It seems to be related to the Powershell 2020.6.0 extension from microsoft for as soon as I enable it the error is thrown.

Any idea on how to get my powershell working again?

2 Answers

Try adding the following in your User Settings (JSON).

{
  "powershell.integratedConsole.suppressStartupBanner": true,
}

Apparently, the Start-EditorServices command being executed with -StartupBanner parameter contains a character (<), which seems to be throwing an error.

The above setting instructs to suppress the startup banner, which resolves this error. I had to spend so many hours of scouring through the internet to finally reach to this discovery. Wish someone in the Powershell Core team would fix this.

I was getting that error because I am using PowerShell 4 (anything less than 5 apparently has this issue).

You can find out what PS version you are using with this command: Get-Host | Select-Object Version

There is a guide of how to install an old version of the PowerShell extension here: https://docs.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

However in brief it says:

  1. Right click on the PowerShell extension and select "Install Another Version..."
  2. Pick version "2020.1.0".

It also suggests disabling auto update. X

Related