PowerShell 7 not available in VS Code

976 Views Asked by At

Running in Windows 11 Pro 64, I've installed PowerShell 7 and VS Code. I'm able to run PS 7 directly in Windows, which brings up a window titled "PowerShell 7 (x64)". In VS Code, I installed the PowerShell extension. When I run VS Code, I'm able to run Windows PowerShell 5.1, but PS 7 does not appear to be available.

I know VS Code is running PS 5.1 and not 7 because when I call Get-Content ... -AsByteStream, it does recognize the parameter AsByteStream.

In VS Code, under "Get Started with PowerShell", there's an item, "Switch Sessions", which says, "To switch between PowerShell 7 and Windows PowerShell 5.1, use the menu: 'Open PowerShell Sessions Menu'" When I click on that button, I get a menu at the top that offers two versions of Windows PowerShell, but no PS 7, as shown in the following display image:

enter image description here

What do I need to do to run PS 7 here?

2

There are 2 best solutions below

0
On

VSCode Settings JSON:

{
    ...
    "terminal.integrated.profiles.windows": {
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "path": [
                "c:/Program Files/PowerShell/7/pwsh.exe" // <- HERE
            ],
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        },
        "Windows PowerShell": null,
    },
    ...
}

You need the line marked with HERE comment.

0
On

Solution found at GitHub.

The problem was that I had installed PS 7 in a custom location, so VS Code didn't know where to look for it.

Solution was to add a VS Code setting: powershell.powerShellAdditionalExePaths with the value being the full filespec of the PS executable, pwsh.exe.

After adding that, the key of that setting appeared in the sessions menu, which allowed me to switch to PS 7, and the parameter AsByteStream was recognized in my script.