Working with PowerShell module downloads from the gallery Follow this step-by-step guide to use AWS Lambda with PowerShell

Best practices for using PowerShell ISE for scripting

Administrators who want to break into PowerShell scripting need to work with an editor for a more effective workflow. Learn how to edit and manage scripts with PowerShell ISE.

When administrators start coding in PowerShell, they need the right tool and the right methods to get the most out of the scripting tool.

The PowerShell Integrated Scripting Environment (ISE) is a Microsoft tool designed to edit, run and manage PowerShell scripts. The editor comes preinstalled with Windows and is simple to use, but there are quite a few features newcomers might not know that can help them build useful scripts.

Execute PowerShell code

PowerShell ISE features two window panes. Admins view and edit code in the top pane and the bottom pane is a PowerShell console.

Whether creating a script from scratch or editing an existing script, you always see the code in the editor window and the output in the console window.

For example, test this script to ensure it works as expected:

if (Test-Path -Path C:\FileDoesNotExist.txt) {
    Write-Host 'The file does not exist'
} else {
    Write-Host 'The file does exist'

PowerShell ISE window panes
The top window pane in PowerShell ISE is where code is written, while the bottom pane shows the output in the PowerShell console.

Admins should run code in chunks to test each piece of code's output. In this case, run the command Test-Path -Path C:\FileDoesNotExist.txt to see what happens. In the ISE editor window, highlight just that code and press the F8 key.

F8 executes code
F8 executes only the highlighted code.

Once you've highlighted and tested each part of the code, press F5 to run the entire script and see how all the code runs together.

Find the right commands with the Command add-on

The Command add-on can help ease scripting in PowerShell ISE. Find the add-on by selecting Show Command add-on in the View menu. A separate window displays a list of the available commands with the parameters and examples of how to use each. The add-on integrates with the PowerShell help system.

The PowerShell ISE Command add-on
The Command add-on in PowerShell ISE lists the available commands and features a search function.

Stay organized with tabs

PowerShell ISE uses the same type of tab navigation as a web browser. You can work on different scripts in multiple tabs. PowerShell ISE has tabs that represent scripts and tabs that represent PowerShell sessions.

When you open PowerShell ISE, you will have one untitled tab running in a single PowerShell session. You can open other script tabs using the Open option in the File menu or create a new script tab via the New option. PowerShell ISE also has a session tab. Navigating up to File and then clicking on New PowerShell Tab creates a different session.

Once you have a few script and session tabs open, you'll see the script tabs appear like child tags of the session tabs.

Script and session tabs
Script tabs are viewed as child tags of the session tabs

The separate sessions in PowerShell ISE help you stay organized when working on multiple scripts. This feature keeps code separate in the editor and creates different PowerShell runspaces. A runspace in PowerShell encapsulates all the variables and functions into its own space. Working with scripts in multiple runspaces prevents stored variables, functions and other code loaded in a particular session from conflicting with one another.

Visual Studio Code vs. PowerShell ISE

When PowerShell 2.0 came out, PowerShell ISE was the first editor designed for the language. Now Microsoft no longer develops PowerShell ISE in favor of Visual Studio Code (VS Code).

VS Code supports multiple languages and has a robust extension gallery to support common features, such as syntax highlighting and an integrated terminal window. VS Code supports PowerShell via an extension and can mirror the functionality of PowerShell ISE. With the cross-platform PowerShell Core as the new scripting and automation focus for Microsoft, this decision makes sense.

Admins that need new functionality or who work with PowerShell on a platform other than Windows should use VS Code. If they only work on Windows and want a simpler, more stable solution to work with and debug PowerShell scripts, PowerShell ISE is an excellent choice.

Next Steps

Use PowerShell workflows when performance matters

How to upload and download files with PowerShell FTP script

Dig Deeper on Windows Server OS and management

Cloud Computing
Enterprise Desktop
Virtual Desktop