Configure Visual Studio Code to run PowerShell for Windows and PowerShell Core Simultaneously
Published Nov 08 2018 03:00 AM 156K Views
Microsoft

I'm a PowerShell fan and have recently adopted PowerShell Core as my version of choice. If you are not familiar with PowerShell Core, it is a cross platform (Windows, Linux, and macOS) version of PowerShell based on .NET Core. That said, I sometimes need to work in PowerShell for Windows or use both side by side.

 

In this post, I will detail how I've used the Shell Launcher Visual Studio Code extension to configure my Windows system to run PowerShell Core and PowerShell for Windows side by side.

 

In order to do this yourself, you need a Windows-based system with both Visual Studio Code and PowerShell Core installed.

 

For more information on PowerShell Core see Installing PowerShell Core on Windows.

 

Configure default PowerShell version

 

Before configuring Shell Launcher, I want to set PowerShell Core as the default PowerShell version. To do so, open up the VS Code user settings.json file by clicking on file > preferences > settings, select ... and then Open settings.json.

 

Modify the settings.json file to include terminal.integrated.shell.windows. The update must be well formed json. If you have other settings in your settings.json file, you may need to adjust the following example.

 

{
    "terminal.integrated.shell.windows": "c:/Program Files/PowerShell/6/pwsh.exe"
}

 

Now, when opening up a terminal in Visual Studio Code, PowerShell core should be the default version.

 

PS C:\storage\code\azure-powershell-demos> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

 

Install the Shell Launcher Visual Studio Code extension

 

The key to opening PowerShell Core and PowerShell for Windows side by side is the Shell Launcher Visual Studio Code extension. Shell Launcher allows you to configure multiple shells within Visual Studio Code.

 

Install the extension by clicking on the Visual Studio Code extensions button and searching the market place for shell launcher. Once located, click install.

 

Thanks a bunch to Daniel Imms for putting together this extension. Be sure to check our more extensions by Daniel, which can be found here - https://marketplace.visualstudio.com/publishers/Tyriar .

 

Configure keyboard bindings for Shell Launcher

 

Before using shell launcher, a key binding needs to be created to engage the shell launcher.

 

Open up the Visual Studio Code keybindings.json file by clicking on file > preferences > Keyboard Shortcuts and then selecting keybindins.json.

 

Add the following to the keybindings.json file to configure ctrl + shift + t as the shell launcher key binding. The update must be well formed json. If you have other settings in your keybindins.json file, you may need to adjust this example.

 

{
"key": "ctrl+shift+t",
"command": "shellLauncher.launch"
}

 

Save and close the file when done.

 

Configure multiple PowerShell terminals

 

Open up the VS Code user settings.json file by clicking on file > preferences > settings, select ... and then Open settings.json.

 

Adding the following to the settings.json file configures two shells, one with PowerShell Core and another with Windows PowerShell. You can adjust the display names (labels), as well as add additional shells such as WSL and CMD.

 

"shellLauncher.shells.windows": [{
        "shell": "c:\\Program Files\\PowerShell\\6\\pwsh.exe",
        "label": "PowerShell Core"
    },
    {
        "shell": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
        "label": "Windows PowerShell"
    }
]

 

PowerShell side by side in action

 

Now, when initiating the Shell Launcher, you should see a menu similar to this. Select the desired version of PowerShell and rock on.

 

shelllauncher1.png

 

To run both versions of PowerShell side by side, open a terminal with the non-default version of PowerShell (PowerShell for Windows in my case), and then click the split terminal button. This will open another side-by-side terminal with the other PowerShell version (PowerShell Core in my case).

 

shelllauncher2.png

 

Fully configured settings.json file

 

For completeness, here is a full copy of a settigns.json file with everything detailed in this post.

 

{

    "terminal.integrated.shell.windows": "c:/Program Files/PowerShell/6/pwsh.exe",

    "shellLauncher.shells.windows": [{
            "shell": "c:\\Program Files\\PowerShell\\6\\pwsh.exe",
            "label": "PowerShell Core"
        },
        {
            "shell": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe",
            "label": "Windows PowerShell"
        }
    ]
} 

 

12 Comments
Copper Contributor
That for a great write-up. The shellLauncher extension is a great find, too.
Microsoft

Appreciate the feedback Rob.

Copper Contributor

Hello Neil,

 

Great write-up! I found this article while searching similar solution... On my computer I have Powershell 5.1 and Powershell Core 6.1.3. I use PS 5.1 for scripts with AzureRm module, and now I want to use PS 6.1 Core for scripts with Az module - I want to have them separated that way. Is there a way to configure VSCode in the way that  scripts using Az module will be debugged in one debugger (debugger profile, etc.. debugged in PS 6.1 in general) and scripts with AzureRm module will use debugger from PS 5.1 ?

 

Thanks!

Copper Contributor

Hi Neil!

Thank you for the info.

 

I must be missing something, Everything seems to be working correctly has I can get multiple session running with different version. My only issue is that when I open a PS1 file and start debugging it always goes back to PowerShell 5 even do I have defined my default shell as 6.2.2 the integrated shell always seems to go back to 5?

 

Any help would be appreciated.

 
Copper Contributor

@Frank_f  : I also see the same thing. Looking for a way to keep the version of the "PowerShell integrated console "to 7 (am using the preview version). Any luck finding the solution yet?

Copper Contributor

To add, in the latest VScode I couldn't find settings.json under ... i.e. file > preferences > settings, select ... and then Open settings.json.

I could find this file by clicking on the file icon in the right corner clipboard_image_0.pngHope this helps to someone working with your post. Thanks for sharing! 

Copper Contributor

Hi, I see that the link to install powershell 6 is not valid anymore, this is the new link.

The Path to which Powershell core is now installed, for me, is going to C:\Users\xxx\vcpkg\downloads\tools\powershell-core-6.2.1-windows

 

When I open VSCode and add this to the settings.json, nothing seems to be happening? Could this also have changed?

 

{
    "terminal.integrated.shell.windows": "C:\Users\xxx\vcpkg\downloads\tools\powershell-core-6.2.1/pwsh.exe"
}

$PSVersionTable still shows the old version. When I look at the terminal, I still only see Powershell Integrated, no extra terminal is coming in.

clipboard_image_0.png

 What am I doing wrong?

 

After that I tried to install the shell launcher, I took over the windows settings in my settings.json, with the path in which it installed at my pc.

clipboard_image_1.png

When I now try to open it with shell launcher, it throws an exception.

clipboard_image_2.png

Copper Contributor

@Pramod_Yadav @Frank_f 
Experiencing the same issue, trying to find a solution to this. I'll post in here if I find one. Keep me up-to-date with your findings also please.

Iron Contributor

 

I have got Visual Studio Code 1.43.1 to successfully toggle between PowerShell Core V7 and Windows PowerShell 5.1 using the ShellLauncher.  PowerShell Core 7 doesn't seem to like it's predecessor, so removes the install directory.

 

 

"terminal.integrated.shell.windows": "C:/Program Files/PowerShell/7/pwsh.exe",    
    "shellLauncher.shells.windows": [{
        "shell": "C:/Program Files/PowerShell/7/pwsh.exe",
        "label": "PowerShell 7 Core"
    },
    {
        "shell": "C:/Windows/system32/WindowsPowerShell/v1.0/powershell.exe",
        "label": "Windows PowerShell 5.1"
    }
    ]

I can use the key mapping in the editor pane to switch the PowerShell version, displayed in the terminal window  drop down version selection  - you don't get the nice label ( see above)  and also you seem to get lots on instances if you repeatedly toggle:

ShellLauncher multiple configs.png

Hope this helps somebody.

Silver Contributor

@Neil Peterson This is a few years old, and seem a bit out of date. Could you please provide an update to help us out TIA

Brass Contributor

This is outdated.

Copper Contributor

This is old. It doesn't work with Visual Studio Code Version 1.76.2.
I'm still looking for a way to use Powershell 5.1 with VSC. It defaults to Powershell 7.3.3 which breaks all of my scripts. Not one single script will run under 7.3.3 without major modifications.

Version history
Last update:
‎Mar 23 2019 07:04 AM
Updated by: