visual-studio-codepowershell-7.0powershell-7.2

Default Powershell Terminal is 7.2 but scripts run as Powershell 5.1


Notice in my VS Code, a fresh terminal, the very first line indicates it is properly defaulted to Powershell 7.2.2 - just as I believe it should.

But then in this same screenshot, the first script I run (which has a command to print out the powershell version) it shows the PSVersion is 5.1.19041.1320

vs code default terminal screenshot

Here's all my powershell specific VSCode entries from settings.json

    "terminal.integrated.profiles.windows": {
        "MyPowerShell_7": {
          "path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
          "args": ["-NoProfile"]
        }
    },
    "terminal.integrated.defaultProfile.windows": "MyPowerShell_7",
    "powershell.powerShellAdditionalExePaths": [
        {
            "exePath": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
            "versionName": "MyPowerShell_7"
        }
    ],
    "powershell.powerShellDefaultVersion": "MyPowerShell_7",

Why why why is it so hard to run the Test-Json cmdlet?


Solution

  • finally found an answer here on reddit

    I didn't know that 5.1 and 7 are side-by-side and have different ways to invoke each application

    So, if I change my command from powershell to pwsh I get the right result

    enter image description here