Skip to main content

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 from this blog

How to list all the AD LDS instances on a server

AD LDS allows you to provide directory services to applications that are free of the confines of Active Directory.  To list all the AD LDS instances on a server, follow this procedure: Log into the server in question Open a command prompt. Type dsdbutil and press Enter Type List Instances and press Enter . You will receive a list of the instance name, both the LDAP and SSL port numbers, the location of the database, and its status.

How to run GPResult on a remote client with PowerShell

In the past, to run the GPResult command, you would need to either physically visit this client, have the user do it, or use and RDP connection.  In all cases, this will disrupt the user.  First, you need PowerShell remoting enabled on the target machine.  You can do this via Group Policy . Open PowerShell and type this command. Invoke-Command –ScriptBlock {GPResult /r} –ComputerName <ComputerName> Replace <ComputerName> with the name of the target.  Remember, the target needs to be online and accessible to you.

Error icon when creating a GPO Preference drive map

You may not have an error at all.  Take a look at the drive mapping below. The red triangle is what threw us off.  It is not an error.  It is simply a color representation of the Replace option of the Action field in the properties of the drive mappings. Create action This give you a green triangle. The Create action creates a new mapped drive for users. Replace Action The Replace action gives you a red triangle.  This action will delete and recreate mapped drives for users. The net result of the Replace action is to overwrite all existing settings associated with the mapped drive. If the drive mapping does not exist, then the Replace action creates a new drive mapping. Update Action The Update action will have a yellow triangle. Update will modify settings of an existing mapped drive for users. This action differs from Replace in that it only updates settings defined within the preference item. All other settings remain as configured on the mapped drive. If the