Windows OS Hub
  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Group Policies
  • Windows Clients
    • Windows 10
    • Windows 8
    • Windows 7
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
  • PowerShell
  • Exchange

 Windows OS Hub / PowerShell / Using Visual Studio Code Instead of PowerShell ISE

April 7, 2020 PowerShell

Using Visual Studio Code Instead of PowerShell ISE

Most administrators use the PowerShell ISE (Integrated Scripting Environment) to build their PowerShell scripts. But by now Microsoft has almost stopped developing PowerShell ISE and recommends using a more powerful, convenient, flexible and free tool instead — Visual Studio Code (VS Code). In this article, we’ll consider how to install, configure and use Visual Studio Code instead of PowerShell ISE to run your PowerShell commands as well as to develop and test complex PowerShell scripts.

VS Code is a cross-platform development environment with a lot of extensions you can use to create a code almost on any programming language. VS Code has the integrated Git support and a vast number of features to work with your code and debug it.

You can download VSCode for free following this link: https://code.visualstudio.com/. Download the VSCodeSetup-x64 installation file (about 53MB) and run it.

VSCode installation does not cause any problems. However, it is recommended to add paths to Visual Studio Code to the environment variable PATH during the installation.

install visual studio code

After starting Visual Studio Code, you will have to install a special free extension that supports PowerShell language — ms-vscode.PowerShell (https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell).

This extension gives you advanced options to work with your PowerShell code: syntax-highlighting, snippets, automatic command hinting (IntelliSense), integrated help and cmdlet browser, interactive script debugging, etc.

You can install the extension from the Extension menu in the left sidebar. Search by powershell key and install the PowerShell extension: Develop PowerShell scripts in Visual Studio Code.

install powershell extension for visual studio code

If you are working in an isolated environment, you can install the extension from a VSIX file. Download ms-vscode.PowerShell-2020.3.0.vsix following the link above and install it using the Install from VSIX menu option.

powershell vsix extension ms-vscode

To make it more convenient, I have configured the following VSCode interface settings (a gear icon in the lower left corner).

workbench.colorTheme = PowerShell ISE – the color scheme is almost alike the familiar one in PowerShell ISE
editor.formatOnType = On
editor.formatOnPaste = On
powershell.integratedConsole.focusConsoleOnExecute = Off
window.zoomLevel = 0
editor.mouseWheelZoom = On

You can also set VSCode settings via JSON file. To do it, click Open Settings (JSON), then copy and paste these settings as plain text here:

{
 "workbench.colorTheme": "PowerShell ISE",
 "editor.formatOnType": true,
 "editor.formatOnPaste": true,
 "powershell.integratedConsole.focusConsoleOnExecute": false,
 "editor.mouseWheelZoom": true,
 "files.defaultLanguage": "powershell",
 "editor.fontSize": 12,
 "terminal.integrated.fontSize": 12,
 "files.encoding": "utf8"
}

ms vscode - powershellshell ise color theme

VSCode supports a lot of shell and programming languages. To switch between them, press F1. In the bar that appears type Change Language mode and select which language syntax you want to use. Select PowerShell and the icon of the file opened in the active tab will change to the PS one.

vs code - powershell editor

Let’s try to use VSCode features to run a PowerShell command and debug scripts.

Create a new project file (it is a common text file). You can work with multiple files simultaneously, they are shown as separate tabs as well and you can switch between them.

Type a simple command to display the list of running processes: Get-Process. As you can see, the IntelliSense technology supports automatic hinting of the command you choose by pressing Tab and the built-in help on the available cmdlet parameters.

powershell cmdlets in visual studio code

In order to execute a single PowerShell command, select the line you need and press F8. If you want to run multiple lines of your PowerShell code, select them with your mouse in the editor window and press F8. You will see the results in the Terminal window. To run the whole PS1 script file, select Terminal -> Run Active File.

In the Terminal window, you can also run PowerShell and cmd.exe commands in the interactive mode.

powershel terminal in vs code

If you are using functions in your PowerShell code, you will go to the function code when you right-click its name and select Go to Definition.

vs code powershell function

Using the integrated script debugger (Ctrl+Shift+D) you can see the variable values, reference values and set break points when running your PowerShell script.

I hope that this article will become a good place to start learning and using rich features of Visual Studio Code to develop your PowerShell scripts.

0 comment
2
Facebook Twitter Google + Pinterest
previous post
MariaDB: Installation and Performance Optimization
next post
How to Configure MariaDB Master-Master/Slave Replication?

Related Reading

Checking User Logon History in Active Directory Domain...

January 22, 2021

Windows 10: No Internet Connection After Connecting to...

January 13, 2021

Updating the PowerShell Version on Windows

December 24, 2020

Restoring Deleted Active Directory Objects/Users

December 21, 2020

Auditing Weak Passwords in Active Directory

December 14, 2020

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange
  • Windows 10
  • Windows 8
  • Windows 7
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2008 R2
  • PowerShell
  • VMWare
  • MS Office

Recent Posts

  • How to Configure and Connect an iSCSI Disk on Windows Server?

    January 26, 2021
  • Preparing Windows for Adobe Flash End of Life on December 31, 2020

    January 22, 2021
  • Checking User Logon History in Active Directory Domain with PowerShell

    January 22, 2021
  • How to Disable/Remove Thumbs.db File on Network Folders in Windows?

    January 21, 2021
  • MS SQL Server 2019 Installation Guide: Basic Settings and Recommendations

    January 19, 2021
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine

    January 15, 2021
  • Windows 10: No Internet Connection After Connecting to VPN Server

    January 13, 2021
  • Updating the PowerShell Version on Windows

    December 24, 2020
  • How to Enable and Configure User Disk Quotas in Windows?

    December 23, 2020
  • Restoring Deleted Active Directory Objects/Users

    December 21, 2020

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Install RSAT Feature on Demand on Windows 10 1809 and Later
  • Get-ADUser: Getting Active Directory Users Info via PowerShell
  • How to Create a UEFI Bootable USB Drive to Install Windows 10 or 7?
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Get-ADComputer: Find Computer Details in Active Directory with PowerShell
  • How to Find the Source of Account Lockouts in Active Directory domain?
  • PSWindowsUpdate: Managing Windows Updates from PowerShell
Footer Logo

@2014 - 2018 - Windows OS Hub. All about operating systems for sysadmins


Back To Top