PowerShell Core is the next version of PowerShell, and is designed to run cross-platform on Windows, Mac, and Linux.

Download the latest version of PowerShell Core that matches your installed operating system from https://github.com/PowerShell/PowerShell/releases taking note of any caveats.

Start Visual Studio Code.

Once loaded open the user settings.json file, via either:

  • use the key combination “CTRL and ,” or
  • press F1 and type settings or
  • via File menu, Preferences, Settings.

On the right hand side, between the { } section, enter the following information, to advise Visual Studio Code that you want to use PowerShell Core, and optionally also change the terminal.

If you already have lines in this file, it’s recommended to make a copy first for backup purposes, and you may also need to change the commas at the end of the lines to ensure that each setting line ends with a comma, apart from the last line.

// Specifies the full path to a PowerShell executable. Changes the installation of PowerShell used for language and debugging services. Select the relevant line that matches the installed OS, replacing version with the version installed.**

// On Windows:

"powershell.developer.powerShellExePath": "c:/Program Files/PowerShell/<version>/powershell.exe"

// On Linux:

"powershell.developer.powerShellExePath": "/opt/microsoft/powershell/<version>/powershell"

// On macOS:

"powershell.developer.powerShellExePath": "/usr/local/microsoft/powershell/<version>/powershell"

// The path of the shell that the terminal uses. Select the relevant line that matches the installed OS.

// On Windows:

"terminal.integrated.shell.windows": "c:/Program Files/PowerShell/<version>/powershell.exe"

// On Linux:

"terminal.integrated.shell.linux": "/opt/microsoft/powershell/<version>/powershell"

// On macOS:

"terminal.integrated.shell.osx": "/usr/local/microsoft/powershell/<version>/powershell"

Visual Studio Code Settings Example settings file that includes the lines above.

Save the settings.json file, then restart code.

To undo these changes, repeat the above but instead of adding the above lines, remove them, taking note to ensure the end of lines commas are matched up as above.

Tip: PS core by default does not know about modules used by the default installation of PowerShell, so many cmdlets will not be available.

To add these, modify the $env:psmodulepath to include:

C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\

You can either add these modules in the code, or by utilising PowerShell profiles. However, relying on profiles can reduces code portability, and some developers prefer not to use profiles in order to reduce the risk of creating external dependencies that complicate running code on different machines.

To use the profile option, add the following line to current PowerShell profile.

$env:psmodulepath = $env:psmodulepath + ";C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\"

You can view the path to this file by typing $Profile into the powershell terminal at the bottom of the Visual Studio Code window.