Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New way to specify Powershell 7 in Visual Studio Code?

I am trying to replace the default Powershell 5 with the newer Powershell 7, on Windows 11.

99% of the solutions on the internet say to add this to settings.json.

"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"

However, this now gives a red squiggly line with the following message:

This is deprecated, the new recommended way to configure your default shell is by creating a terminal profile in #terminal.integrated.profiles.windows# and setting its profile name as the default in #terminal.integrated.defaultProfile.windows#. This will currently take priority over the new profiles settings but that will change in the future.(2)

There is one possibly related thread, but it only deals with defaulting it to the native Command Prompt, rather than re-jigging things to Powershell 7.

So, what is the correct new way to provide Powershell 7s path to VS Code, and also set it as the default terminal?

like image 979
Larry Cai Avatar asked Dec 03 '25 03:12

Larry Cai


2 Answers

Preface:

  • The solution below addresses the question as asked, involving modification of the settings.json file.

  • However, there is now a GUI method available that allows you to pick the default profile more conveniently, assuming that your PowerShell (Core) 7 installation is in a standard location known to Visual Studio Code - see Lee Grissom's answer.
    For installations not auto-discoverable by Visual Studio Code or for customizing the startup options of existing profiles you'll still need the settings.json method, however.

  • Both methods relate to use of PowerShell 7 as the default general-purpose shell in Visual Studio Code's integrated terminal.

    • By contrast, if you have the PowerShell extension installed (for authoring and debugging PowerShell code) and want to control what edition / version is being used in its special-purpose shell, the PIC (PowerShell-Integrated Console), see this answer.

In earlier VSCode (Visual Studio Code) versions, the "terminal.integrated.shell.*" and "terminal.integrated.shellArgs.*" settings determined the default shell and its startup arguments for the integrated terminal.

These have been superseded by shell profiles, defined via "terminal.integrated.profiles.*" properties and an associated "terminal.integrated.defaultProfile.*" property that contains the name of the profile to use by default, as shown below.

// Excerpt from settings.json
"terminal.integrated.profiles.windows": {
    "PowerShell_7": {
      "path": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
      "icon": "terminal-powershell"
    },  // ...
}

// Make the profile defined above the default profile.
"terminal.integrated.defaultProfile.windows": "PowerShell_7" 

Note:

  • Open your settings.json file for editing as follows: From the command palette (select menu command View > Command Palette... or press Ctrl+Shift+P), select command Preferences: Open User Settings (JSON); searching for user json should be enough to locate it.

  • I would have expected Visual Studio Code to use your v7 version automatically, as it - if installed - normally takes precedence over Windows PowerShell.

like image 191
mklement0 Avatar answered Dec 04 '25 21:12

mklement0


Source: https://code.visualstudio.com/docs/terminal/profiles#_windows-powershell

When PowerShell 6+ is installed, Windows PowerShell is not included in the profiles list by default. To add Windows PowerShell as a profile, choose the Select Default Profile option in the new terminal dropdown and select the Windows PowerShell item. This will configure the profile and set it as your default.

Select Default Profile Menu Item Select PowerShell exe

like image 26
Lee Grissom Avatar answered Dec 04 '25 23:12

Lee Grissom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!