Migrating from PowerShell ISE to Visual Studio Code

In this blog post I’ll share a number of resources for how to move from the PowerShell ISE to Visual Studio Code for writing and executing PowerShell scripts.

See the source image

Background

Much of the content from this post is sourced from two other excellent resources:

In my working with various customers many times we are working on PowerShell scripts together.  I’ve noticed that many are still using the PowerShell ISE as their primary host for developing and executing PowerShell snippets or scripts.  Back in May 2017 the PowerShell team announced the shift of focus from PowerShell ISE to Visual Studio Code with the Announcing PowerShell for Visual Studio Code 1.0! blog post.  Combining the move to PowerShell Core (v6) (based on .Net Core which is cross-platform) with the limitation that the PowerShell ISE is Windows-only meant a change in direction was needed.

In the following sections I’ll overview a number of steps for getting up and running with PowerShell in Visual Studio Code.

Visual Studio Code

The first step is to install Visual Studio Code.  If you’ve feared it because it has the words “Visual Studio” in the name don’t worry.  Visual Studio Code is really a text editor (think Notepad) with really powerful extensions that you can add.  I recommend the “user install” vs. “system install” as the former doesn’t require Administrator rights.

PowerShell extension

The next step is to install the PowerShell extension for Visual Studio Code.  This extension provides syntax highlighting, intellisense, running scripts with F8, and more.

One important change to the Visual Studio Code setting that I found especially helpful is keeping the focus on the editor window (not the console) when executing scripts.  Update the following setting to configure this.

"powershell.integratedConsole.focusConsoleOnExecute": false

Shell Launcher extension

If you have a need to regularly switch between multiple shells (PowerShell v5 / v6 / v7-preview, Git Bash, Windows Subsystem for Linux (WSL) Bash, CMD, etc.) like I do the Shell launcher extension is helpful.  Be sure to follow the instructions for setting a keybinding for switching shells (suggested “Ctrl+Shift+T” on Windows).  In my case this keybinding was already used by another extension but I was okay with overwriting that.

PSISEtoVSCode2
Keybinding for Shell Launcher to launch a shell

The following are the settings I use for the multiple shells:

"shellLauncher.shells.windows": [
        {
            "shell""C:\\Program Files\\PowerShell\\6\\pwsh.exe",
            "label""Pwsh Core"
        },
        {
            "shell""C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
            "label""PSv7 (preview)"
        },        {
            "shell""C:\\Windows\\System32\\wsl.exe",
            "label""WSL zsh"
        },
        {
            "shell""C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
            "label""PowerShell (v5)"
        },
        {
            "shell""C:\\Windows\\System32\\cmd.exe",
            "label""cmd"
        },
        {
            "shell""C:\\Program Files\\Git\\bin\\bash.exe",
            "label""Git bash"
        },
        {
            "shell""C:\\Windows\\System32\\bash.exe",
            "label""WSL Bash"
        }
    ],

 

Bonus – ZSH and auto-suggest

I’ll be the first to admit that I don’t use Windows Subsystem for Linux (WSL) often.  That said there are times I find it helpful to run the Azure CLI on a WSL shell though.  An example is when I’m doing demos or presentations and I want to showcase the auto-suggest feature in Zsh (short for “Z shell”).  Not only does the auto-suggest help me remember what commands to type but it lets the audience follow along more easily.  See the following links for installing and configuring.

 

PSISEtoVSCode1
Example Zsh auto-suggest with Azure CLI

Conclusion

In this article I walked through a number of useful extensions or configurations to help migrate from the Windows-only PowerShell ISE to the cross-platform Visual Studio Code.  If you have additional suggestions or tips please share them in the comments.

-Frog Out

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s