My VSCode Configuration for PowerShell







Two weeks ago, I had the honor of delivering a workshop at PowerShell Conference Asia in Bangalore.  My workshop was called Zero to Hero where I taught the fundamentals of PowerShell with the goal of allowing the conference attendees to have the confidence to attend the rest of the high-level sessions.  It was a success!  With 60 PowerShell enthusiasts enrolled, the organizers had to close registration.

I made the decision to utilize VSCode as our scripting platform to get the attendees on the path from the ISE to VSCode.  One of the first questions given to the PowerShell team members at the conference was “Will there be an ISE for PowerShell 7”.  Their answer, “No”.  I also made the decision to deliver the class using the just released PowerShell 7-Preview 4.  This version addressed several issues that I had with Preview 1-3.  It is not perfect, but it is now at the performance and reliability level that I want and I am teaching it in my Windows PowerShell classes.

One of the challenges for my fellow PowerShell Rock Stars will be the mental conversion from the ISE to VSCode.  I am going to share my extensions and configuration files and settings for how I have VSCode set up for my students and I.

These instructions assume that you have already installed PowerShell 7 and VSCode.  Remember, update your version of PowerShell 7 if you do not have Preview 4 or higher. I am getting happier with it with each new release.

Here are the 3 extensions that I have my students add to VSCode
PowerShell
Shell Launcher
FontSize

The PowerShell extension is a must.  This is how VSCode knows how to use PowerShell.
Shell Launcher will allow us to easily open multiple terminal windows with different versions of PowerShell.
FontSize allows you to increase and decrease the font sizes easily by pressing Ctrl + and Ctrl -.

Once all of these are installed, open your Settings File from the File menu.




Below is my settings.json file.
{

    "terminal.integrated.shell.windows""C:\\Program Files\\PowerShell\\7-preview\\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"
        }
    ],
    "window.zoomLevel"2,
    "files.autoSave""afterDelay",
    "files.defaultLanguage""powershell",
    "powershell.startAutomatically"true,
    "powershell.powerShellExePath""C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
    "editor.lineHeight"0,
    "editor.fontSize"19,
    "terminal.integrated.fontSize"17,
    "terminal.integrated.rendererType""dom",
    "workbench.colorTheme""Tomorrow Night Blue"

    

Feel free to copy and paste or add to your current settings.json file.
Next are the KeyBindings.
From the File menu, open your Keyboard Shortcuts and then the keybindings.json file



Here are my current settings.
// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key""f5",
        "command""workbench.action.terminal.runActiveFile"
    },
    {
        "key""f8",
        "command""workbench.action.terminal.runSelectedText"
    },
    {
        "key""ctrl+k",
        "command""workbench.action.terminal.clear"
    },
    {
        "key""ctrl+m",
        "command""editor.foldAllMarkerRegions",
        "when""editorTextFocus"
    },
    {
        "key""ctrl+k ctrl+8",
        "command""-editor.foldAllMarkerRegions",
        "when""editorTextFocus"
    },
    {
        "key""ctrl+n",
        "command""editor.unfoldAllMarkerRegions",
        "when""editorTextFocus"
    },
    {
        "key""ctrl+k ctrl+9",
        "command""-editor.unfoldAllMarkerRegions",
        "when""editorTextFocus"
    },
    {
        "key""ctrl+r",
        "command""workbench.action.toggleMaximizedPanel"
    },
    {
        "key""ctrl+shift+t",
        "command""shellLauncher.launch"
    }
]

I’m continuously working to try and provide an experience that closely mimics the PowerShell ISE.  We know that it is going away, but we can still try to mimic the ease of use that it has.

#PowerShell #VSCode #PowerShellTraining #PSConfAsia @PSConfAsia


Comments

Popular Posts