Fixing VSCode PowerShell Issues (Part 2)

by Mar 2, 2021

If VSCode won’t launch a PowerShell engine when editing a PowerShell script and instead the yellow message “Starting PowerShell” in the status bar won’t go away, then one possible fix is to use a fresh and separate portable install of PowerShell 7 as the default PowerShell engine in VSCode.

First, run this line to create the cmdlet Install-PowerShell:

Invoke-RestMethod -Uri https://aka.ms/install-powershell.ps1 | New-Item -Path function: -Name Install-PowerShell | Out-Null

Next, install a fresh copy of PowerShell7 in a local folder, for example:

Install-PowerShell -Destination c:\portablePowerShell

After installation completes, make sure you can manually launch your new PowerShell instance:

c:\portablePowerShell\pwsh

Now go ahead and tell VSCode that you’d like to use this new instance of PowerShell to run when editing PowerShell scripts: in VSCode, choose File/Preferences/Settings, click on Extensions in the left column of settings, and click “PowerShell Configuration” in its submenu.

Next, search for the setting “PowerShell Default Version”, and enter any name, i.e. “portable PowerShell 7”. In the section above called “PowerShell Additional Exe Paths”, click on the link “Edit in settings.json”. This opens the raw settings file in JSON format.

In it, the new setting section is already inserted and needs to be completed like this:

"powershell.powerShellAdditionalExePaths": [
        {
            "exePath": "c:\\portablePowerShell\\pwsh.exe",
            "versionName": "portable PowerShell 7"
        }
    ]

Attention: all tags and keywords are case-sensitive, and in paths, the backslash needs to be escaped by another backslash. In “exePath”, specify the path to the pwsh.exe file inside your downloaded portable PowerShell folder. Make sure the path points to pwsh.exe, not just to the folder.

In “versionName”, use the same label name you specified in “PowerShell Default Version” before.

Once you save the JSON file, restart VSCode. The editor now uses your portable PowerShell 7, and in many instances, this solves stalled PowerShell startup problems.

The recipe above also is useful if you’d like to manually add additional PowerShell versions to VSCode. When you click the green PowerShell version in the VSCode status bar, any manually added PowerShell will appear in the selection dialog (unless it is already being used in which case the menu shows the PowerShell type and version instead of your label name).


Twitter This Tip! ReTweet this Tip!