Most directors use the PowerShell ISE (Integrated Scripting Environment) to construct their PowerShell scripts. But by now Microsoft has virtually stopped growing PowerShell ISE and recommends utilizing a extra highly effective, handy, versatile and free device as a substitute — Visual Studio Code (VS Code). In this text, we’ll think about the best way to set up, configure and use Visual Studio Code as a substitute of PowerShell ISE to run your PowerShell instructions in addition to to develop and check advanced PowerShell scripts.
VS Code is a cross-platform improvement setting with so much of extensions you should utilize to create a code virtually on any programming language. VS Code has the built-in Git assist and an unlimited quantity of options to work together with your code and debug it.
You can obtain VSCode without cost following this hyperlink: https://code.visualstudio.com/. Download the VSCodeSetup-x64 set up file (about 53MB) and run it.
VSCode set up doesn’t trigger any issues. However, it is strongly recommended so as to add paths to Visual Studio Code to the setting variable PATH through the set up.
After beginning Visual Studio Code, you’ll have to set up a particular free extension that helps PowerShell language — ms-vscode.PowerShell (https://market.visualstudio.com/objects?itemName=ms-vscode.PowerShell).
This extension provides you superior choices to work together with your PowerShell code: syntax-highlighting, snippets, computerized command hinting (IntelliSense), built-in assist and cmdlet browser, interactive script debugging, and so forth.
You can set up the extension from the Extension menu within the left sidebar. Search by
powershell key and set up the PowerShell extension: Develop PowerShell scripts in Visual Studio Code.
If you’re working in an remoted setting, you possibly can set up the extension from a VSIX file. Download ms-vscode.PowerShell-2020.three.zero.vsix following the hyperlink above and set up it utilizing the Install from VSIX menu choice.
To make it extra handy, I’ve configured the next VSCode interface settings (a gear icon within the decrease left nook).
workbench.colorTheme = PowerShell ISE – the colour scheme is nearly alike the acquainted one in PowerShell ISE
editor.formatOnType = On
editor.formatOnPaste = On
powershell.integratedConsole.focusConsoleOnExecute = Off
window.zoomLevel = zero
editor.mouseWheelZoom = On
You can even set VSCode settings through JSON file. To do it, click on Open Settings (JSON), then copy and paste these settings as plain textual content right here:
Let’s attempt to use VSCode options to run a PowerShell command and debug scripts.
Create a brand new undertaking file (it’s a widespread textual content file). You can work with a number of recordsdata concurrently, they’re proven as separate tabs as effectively and you’ll change between them.
Type a easy command to show the record of operating processes: Get-Process. As you possibly can see, the IntelliSense technology helps computerized hinting of the command you select by urgent Tab and the built-in assistance on the accessible cmdlet parameters.
In order to execute a single PowerShell command, choose the road you want and press F8. If you wish to run a number of strains of your PowerShell code, choose them together with your mouse within the editor window and press F8. You will see the ends in the Terminal window. To run the entire PS1 script file, choose Terminal -> Run Active File.
In the Terminal window, you can even run PowerShell and cmd.exe instructions within the interactive mode.
If you’re utilizing capabilities in your PowerShell code, you’ll go to the perform code once you right-click its title and choose Go to Definition.
Using the built-in script debugger (Ctrl+Shift+D) you possibly can see the variable values, reference values and set break factors when operating your PowerShell script.
I hope that this text will develop into an excellent place to start out studying and utilizing wealthy options of Visual Studio Code to develop your PowerShell scripts.