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.

Where did a User’s Account Get Locked Out?

Updated: May 15, 2015 When this article was originally published, two extra carriage returns were add causing the code to malfunction.  The code below is correct.   My client for this week’s PowerShell class had a really interesting question. They needed to know where an account is being locked out at. OK, interesting. Apparently users hop around clients and forget to log off, leading to eventual lock out of their accounts. The accounts can be unlocked, but are then relocked after Active Directory replication. This problem is solved in two parts. The first one is to modify the event auditing on the network. The second part is resolved with PowerShell. The first part involves creating a group policy that will encompass your Domain Controllers. In this GPO, make these changes. Expand Computer Configuration \ Policies \ Windows Settings \ Security Settings \ Advanced Audit Policy Configuration \ Audit Policies \ Account Management Double click User Account Management C...