Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2012
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 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
7
Facebook Twitter Google + Pinterest
previous post
MariaDB: Installation and Performance Optimization
next post
How to Configure MariaDB Master-Master/Slave Replication?

Related Reading

Using Previous Command History in PowerShell Console

January 31, 2023

How to Install the PowerShell Active Directory Module...

January 31, 2023

Finding Duplicate E-mail (SMTP) Addresses in Exchange

January 27, 2023

How to Disable or Uninstall Internet Explorer (IE)...

January 26, 2023

How to Delete Old User Profiles in Windows?

January 25, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Using Previous Command History in PowerShell Console

    January 31, 2023
  • How to Install the PowerShell Active Directory Module and Manage AD?

    January 31, 2023
  • Finding Duplicate E-mail (SMTP) Addresses in Exchange

    January 27, 2023
  • How to Delete Old User Profiles in Windows?

    January 25, 2023
  • How to Install Free VMware Hypervisor (ESXi)?

    January 24, 2023
  • How to Enable TLS 1.2 on Windows?

    January 18, 2023
  • Allow or Prevent Non-Admin Users from Reboot/Shutdown Windows

    January 17, 2023
  • Fix: Can’t Extend Volume in Windows

    January 12, 2023
  • Wi-Fi (Internet) Disconnects After Sleep or Hibernation on Windows 10/11

    January 11, 2023
  • Adding Trusted Root Certificates on Linux

    January 9, 2023

Follow us

woshub.com
  • Facebook
  • Twitter
  • RSS
Popular Posts
  • Installing RSAT Administration Tools on Windows 10 and 11
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • How to Hide Installed Programs in Windows 10 and 11?
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • How to Create a UEFI Bootable USB Drive to Install Windows 10 or 7?
  • PowerShell: Get Folder Sizes on Disk in Windows
  • Deploy PowerShell Active Directory Module without Installing RSAT
Footer Logo

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


Back To Top