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

Adding a Comment to a GPO with PowerShell

As I'm writing this article, I'm also writing a customization for a PowerShell course I'm teaching next week in Phoenix.  This customization deals with Group Policy and PowerShell.  For those of you who attend my classes may already know this, but I sit their and try to ask the questions to myself that others may ask as I present the material.  I finished up my customization a few hours ago and then I realized that I did not add in how to put a comment on a GPO.  This is a feature that many Group Policy Administrators may not be aware of. This past summer I attended a presentation at TechEd on Group Policy.  One organization in the crowd had over 5,000 Group Policies.  In an environment like that, the comment section can be priceless.  I always like to write in the comment section why I created the policy so I know its purpose next week after I've completed 50 other tasks and can't remember what I did 5 minutes ago. In the Group Policy module for PowerShell V3, th

Return duplicate values from a collection with PowerShell

If you have a collection of objects and you want to remove any duplicate items, it is fairly simple. # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   # Remove the duplicate values. $Set1 | Select-Object -Unique 1 2 3 4 5 6 7 What if you want only the duplicate values and nothing else? # Create a collection with duplicate values $Set1 = 1 , 1 , 2 , 2 , 3 , 4 , 5 , 6 , 7 , 1 , 2   #Create a second collection with duplicate values removed. $Set2 = $Set1 | Select-Object -Unique   # Return only the duplicate values. ( Compare-Object -ReferenceObject $Set2 -DifferenceObject $Set1 ) . InputObject | Select-Object – Unique 1 2 This works with objects as well as numbers.  The first command creates a collection with 2 duplicates of both 1 and 2.   The second command creates another collection with the duplicates filtered out.  The Compare-Object cmdlet will first find items that are diffe

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.