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:

vscode-terminal1a

There’s a setting in the default settings that references cmd.exe as the terminal:

vscode-terminal2a

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:

vscode-terminal3b

Save the settings.json file. Close and reopen VS Code.

Open the Integrated Terminal from View > Integrated Terminal or with the Ctrl + ` keyboard shortcut:

vscode-terminal4a

Now you can run PowerShell code via the PowerShell console right from within Visual Studio Code:

vscode-terminal5b

I also found the following two Visual Studio documentation articles helpful and interesting:

User and Workspace Settings
Markdown and VS Code

µ

9 Comments

  1. vernanderson

    Mike you never cease to amaze me!!!

    Reply
  2. don

    Nice article. How can I get my integrated PowerShell terminal in VS Code to have color coded text like yours? Mine is just gray on black.

    Reply
  3. David Wallis

    Dont suppose you know if you can change the right click on a folder from CMD to powershell do you???

    Reply
  4. Winsto

    Nice one, thank you.

    Reply
  5. powershell nubie

    I use windows 10, I tried the above and it does not work, when I did the above.

    which version of windows are you using for the above tweak

    Reply
  6. anony

    I will keep using ISE. ISE is still far better than visual studio code. Its intellisense is far superior , e.g if you run this line in the ISE editor

    $myresponse = Invoke-RestMethod -Uri http://services.groupkt.com/state/get/IND/all

    then if you go to the integrated terminal/console in ISE, you can type $myresponse. and and its intellisense jumps in right away with the contents of $myresponse

    it allows you to drill down into the $myresponse and will display “restresponse” then “result” and “messages” so that you can just select the one you need and drill down to the level of information you want.

    try this in VSCODE, its intellisense does not even detect and display “restresponse”, “result”, “messages” .

    Reply

Leave a Reply

%d bloggers like this: