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.
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
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 .
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.
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"
}
]
Now, when initiating the Shell Launcher, you should see a menu similar to this. Select the desired version of PowerShell and rock on.
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).
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"
}
]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.