Use the PowerShell Console from within Visual Studio Code
I recently revisited Visual Studio Code. I was looking for a markdown editor and remembered seeing a tweet a few weeks ago saying that VS Code could be used to edit markdown. It supports markdown by default, although I would recommend adding a spell check extension to it.
I thought that it would be convenient if I could write my PowerShell code right from within the same interface that I'm writing other things such as markdown. One of the problems that I previously experienced with VS Code is there wasn't a PowerShell console pane like in the ISE (Integrated Scripting Environment). Based on the release notes for VS Code, back in May of 2016, version 1.2.0 was released and added support for an Integrated Terminal which uses the cmd.exe command prompt by default on a Windows system. As you'll see in this blog article, it's really easy to change the integrated terminal to use PowerShell.exe instead of cmd.exe.
If you haven't already installed Visual Studio Code and the PowerShell extension for it, take a look at my blog article titled Installing Visual Studio Code and the PowerShell Extension.
Open VS Code. Select File > Preferences > User Settings
:
There's a setting in the default settings that references cmd.exe
as the terminal:
A settings.json
file is also opened when User Settings
is selected. It allows any of the default
settings to be overwritten. Based on the
Integrated Terminal documentation
page that was previously referenced, place the following entry in the settings.json file to make
PowerShell.exe the default integrated terminal program:
1// 64-bit PowerShell if available, otherwise 32-bit
2"terminal.integrated.shell.windows":"C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
Save the settings.json
file. Close and reopen VS Code.
Open the Integrated Terminal from View > Integrated Terminal
or with the Ctrl + \
keyboard
shortcut:
Now you can run PowerShell code via the PowerShell console right from within Visual Studio Code:
I also found the following two Visual Studio documentation articles helpful and interesting:
µ