Home
Microsoft

Configure Visual Studio Code to run PowerShell for Windows and PowerShell Core Simultaneously

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"
        }
    ]
} 

 

2 Comments
Occasional Visitor
That for a great write-up. The shellLauncher extension is a great find, too.
Microsoft

Appreciate the feedback Rob.