In this article, I'll show you how to work with multiple shells such as PowerShell Core 6.0 and Windows PowerShell 5.1 side by side in Microsoft Visual Studio Code (VSCode). You'll notice VSCode is not only a great scripting environment but also an excellent PowerShell console.

Michael Pietroforte

Michael Pietroforte is the founder and editor in chief of 4sysops. He has more than 35 years of experience in IT management and system administration.

Microsoft Visual Studio Code (VSCode) supposedly replaces PowerShell ISE and is perhaps the best free code editor for PowerShell. The nice thing about VSCode is that you can integrate any shell including different PowerShell versions, cmd.exe, and bash.

Why Visual Studio Code ^

Note that on Microsoft sites you'll often find the abbreviation "VS Code" instead of "VSCode" for Visual Code. But Google says VSCode is more common, so I'll stay with the recommendation of the #1 spelling expert on the planet.

You've probably heard the news that PowerShell Core 6 is out and that Windows PowerShell has no future. This also means that the PowerShell ISE that still ships with Windows 10 will soon be history. Thus, the earlier you move on, the better it will be for your career because you will stay ahead of the pack.

Visual Studio Code for Windows

Visual Studio Code for Windows

This doesn't necessarily mean you also have to move from PowerShell 5.1 to PowerShell 6, because VSCode works well with Windows PowerShell. Actually, VSCode has been available since 2015 and supports all common programming languages. You can run PowerShell 5.1 and PowerShell Core 6.0 on the same Windows computer and integrate both shells in VSCode. This is very useful if you want to test whether your old scripts also work in PowerShell Core.

A (long) while back I argued in a blog post (which became quite popular) that PowerShell ISE is a better terminal than the PowerShell console. I still don't like the PowerShell console because its interface lacks many features of modern terminals, and it still is essentially the same ol' MS-DOS console. Heck, the PowerShell console doesn't even support tabs.

The PowerShell 6 Console looks like MS DOS

The PowerShell 6 Console looks like MS DOS

A downside of PowerShell ISE as a terminal is that it sometimes behaves a bit differently than the PowerShell console does. Thus, if something doesn't work as expected, you always wonder whether ISE was the culprit. The good news is that this isn't to be expected with VSCode, because it just integrates the installed shells. For instance, if you install VSCode on Linux or macOS, you can also integrate bash, and on Windows you can work with cmd.exe (see below).

Install Visual Studio Code ^

To get started, download Visual Studio Code. And since you are already in the browser, you might as well download PowerShell 6 for all the operating systems you love. I will only cover Windows here, but I am also working with VSCode and PowerShell Core on a Mac, and it is essentially all the same. The only differences I've noticed so far are a few keyboard shortcuts are a bit different and the configuration files need to know the OS where VSCode runs on.

When you first launch VSCode, an error message will greet you:

Warn Git not found. Install it or configure it using the 'git path' setting.
Git installation not found

This is not a good a way to introduce a newly installed tool. Git is a version control system, and I think not every Windows admin will need it. But if you want a complete development environment, head over to the Git download page.

Don't make the mistake of opening the Git release notes with VSCode as the wizard suggests. This will cause trouble if Git hasn't initialized yet. When you restart VSCode after installing Git, the warning message will be gone.

You now already have a nice scripting environment for PowerShell. The Windows PowerShell 5.1 console is also already integrated. Click on the Terminal tab.

Terminal tab in VSCode with PowerShell 5.1 console

Terminal tab in VSCode with PowerShell 5.1 console

VSCode and PowerShell Core 6.0 ^

What is still missing is the PowerShell Core 6 integration. To integrate PowerShell 6, follow the menu path File menu > Preferences > Settings, add the line below to the user settings file (settings.json), and then hit Ctrl+S to save the settings.

Integrating PowerShell 6 Core in VSCode

Integrating PowerShell 6 Core in VSCode

Note that the exact location of pwsh.exe depends on your operating system and the PowerShell version. After you restart VSCode, PowerShell 6 is the new integrated terminal.

PowerShell 6.0.1 in VSCode

PowerShell 6.0.1 in VSCode

This is fine as long as PowerShell 6 is the only console you need, but I suspect you'll also want to work with other shells such as PowerShell 5.1 and cmd. As far as I know, there is no setting for this in VSCode. However, the really cool thing about VSCode is that many great extensions exist. Coincidentally, one such extension allows you to work with multiple shells in VSCode.

Multiple consoles in VSCode ^

To install Shell Launcher, click the extension icon in the left navigation bar and then type "shell launcher."

Installing Shell Launcher from the VSCode marketplace

Installing Shell Launcher from the VSCode marketplace

Next, open the user settings again to add the lines below:

You now have to click the Reload button.

Reloading VSCode

Reloading VSCode

Note that the exact locations may vary depending on your operating system and shell version. If you want, you can remove the line we added above to set PowerShell 6 as the default shell. That way, PowerShell 5.1 will be your default shell (not really the recommended option).

To launch one of the new integrated consoles, open the Command Palette in the View menu or press Ctrl+Shift+P. Then start typing "shell launcher" and select the extension. You should now see the new shells.

Launching Shell Launcher

Launching Shell Launcher

Select the shell you want to work with and hit Enter.

Starting a new shell

Starting a new shell

Once you start a new shell this way, it will stay open until you close VSCode. You can switch between shells in the Terminal tab as shown in the screenshot below.

Switching between shells

Switching between shells

You can also work with multiple consoles of the same shell by clicking the + icon.

You might feel always going through the Command Palette is too longwinded to start a new shell in the Terminal tab. If so, you can assign a keyboard shortcut to Shell Launcher. Navigate to the Keyboard Shortcuts (File > Preferences) and start typing "shell launcher." Then double-click the extension and assign your shortcut (for instance, Ctrl+Shift+T).

Assigning a keyboard shortcut to Shell Launcher

Assigning a keyboard shortcut to Shell Launcher

In my next post, I will show you how you can add more features to VSCode with the PowerShell extension and explain how you can conveniently execute code from the editor just like you're familiar with from PowerShell ISE.

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

9+

Users who have LIKED this post:

  • avatar
  • avatar
  • avatar
Share
11 Comments
  1. Allan Weaver 2 years ago

    Thanks for the article, Michael. I wondered how to use VSCode with Powershell 6.0.
    Now I know. I want to stay ahead of the pack!
    I look forward to your future articles on this topic.
    I run Powershell 6.0 on Windows 8.1. I never did go to 10.

    1+

    • Author
      Michael Pietroforte 2 years ago

      Allan, thanks! I suppose it makes no difference if you work with PowerShell on Windows 8.1 or Windows 10. However, as an IT pro I think it is important to always use the latest technologies even if you think the upgrade brings no direct advantages to you. You have to use Windows 10 yourself on a daily basis to learn all about it. It doesn't really matter if you like it or not. All that matters for an IT pro is that you know it.

      That is why I recommend working with PowerShell Core asap even if offers fewer features than Windows PowerShell. I also recommend using it on different platforms because it will certainly be helpful for your career.

      2+

  2. Milos Mitic 2 years ago

    Thank you for this article Michael.

    I was going to install VSCode for a long time and now I finally did it along with pwsh 🙂

    I look forward to your next post about adding more features to VSCode.

    1+

    • Author
      Michael Pietroforte 2 years ago

      Milos, thanks for the comment. That was the intention of the article. If you move to PowerShell Core together with VSCode it feels more like that you made a technology leap even though pwsh still lacks many features of 5.1. However, for me the real enlightenment was that I suddenly can work with PowerShell on different platforms. That makes the language much more valuable for me and I believe that this the main technological advancement here. In particular, if I am in VSCode it makes no real difference if I work on Windows or on a Mac. I think this is really cool.

      2+

      Users who have LIKED this comment:

      • avatar
  3. James mccarte 2 years ago

    These suggestions don't work with Visual Studio Code 1.23, PowerShell Core 6.1 Preview 2, and Windows 10

    1+

    • Author
      Michael Pietroforte 2 years ago

      Thanks for the hint. I think it is too early to work with PowerShell Core 6.1 because as far as I know it is not feature-complete. Thus, we have to wait until the final release to see if this guide will still work with PowerShell 6.1.

      1+

  4. Culip 1 year ago

    Thanks for helping me implement PowerShell Core 6 into Visual Studio Code.

    But it doesn't have cool features like auto-completion that are available in PowerShell ISE..

    1+

  5. Aaron Axvig 1 year ago

    If you just do "terminal.integrated.shell.windows": "pwsh.exe" then it doesn't matter which version of PowerShell you have installed, and it should continue to work when it gets updated to a new version in the future.  (Assuming pwsh.exe is on your path.)

    3+

    Users who have LIKED this comment:

    • avatar
    • Luc Fullenwarth 1 year ago

      Seems like the PowerShell team decided to put all versions in the same directory: C:\Program Files\PowerShell\6

      At least that's true for version 6.1

      But I keep your tip just in case they change their mind 😉

      1+

      Users who have LIKED this comment:

      • avatar
  6. Mike Campbell 1 year ago

    Hi Michael, I'm using VS Code as my daily editor in most cases but I haven't been able to make the transition to using it as my daily console of choice due to one problem that I was hoping the Shell Launcher extension would fix. That problem is, if you use the File -> Open Folder to open a local repository VSCode kills your existing sessions and re-opens a new default.  Too bad if you had history, jobs, variables, error history, etc. that you wanted to reference.  It's all gone.  Personally, I'd love to see a replacement for ISE that gave us VSCode functionality in the editor and a separate tabbed console experience that wouldn't do the above.

    1+

    • Author

      Yeah I know the problem. However, the behavior of ISE here is problematic too because it often appears that a script works correctly and if you then deploy it you notice that it does not work in a production environment because some variable values that have been available in your ISE session are missing. Thus, even if this means a little extra work sometimes, the behavior of Code makes a lot of sense.

      1+

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2019

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account