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

Determine which Domain Controller a client is connected to with PowerShell

When a Windows client comes online, it must find a domain controller to bind to.  Either through a static configuration or DHCP, the client will request a list of all Domain Controllers in the domain from a DNS server.  Once the list is received, the client will randomly go through the list to find a DC that will respond.  Once the client has authenticated itself with the DC, the DC will transmit the site information to the client.  The site information will contain the site name, the subnet(s) associated with that site, and any domain controllers in that site.  The client will then take a look at it’s own IP address to determine which site it is in.  From the list of DCs in the same site, it will attempt to bind to one of those DCs to receive it’s Group Policies.You can use PowerShell and WMI to locate the domain controller that a client is connected to.Get-WMIObject Win32_NTDomainLook for the DomainControllerName property.

Test to see what that data type of a value is in PowerShell

PowerShell has a comparison operator called –is.  The –is operator simply response True or False when you use it to verify the data type of a value.  The valid data types in PowerShell are:
[string]    Fixed-length string of Unicode characters
[char]      A Unicode 16-bit character
[byte]      An 8-bit unsigned character
[int]       32-bit signed integer
[long]      64-bit signed integer
[bool]      Boolean True/False value
[decimal]   A 128-bit decimal value
[single]    Single-precision 32-bit floating point number
[double]    Double-precision 64-bit floating point number
[DateTime]  Date and Time
[xml]       Xml object
[array]     An array of values
[hashtable] Hashtable object

Below is a script that will use –is to test some values.
$String="Hello"$Boolean=$True$Int=15Write-Host"Test for string"$String-is [String] $Boolean-is [String] $Int-is [String] Write-Host" "Write-Host"Test for Boolean"…

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 ManagementDouble click User Account ManagementCheck Configure the f…