Windows PowerShell ISE Fundamentals

One of the primary reasons we have the Windows PowerShell Integrated Scripting Environment (ISE) is so that you have something other than Notepad for creating PowerShell scripts. On client operating systems, the PowerShell ISE should be installed by default. On servers it is an optional feature.

Launching the PowerShell ISE from the command prompt

Because you are probably not developing scripts on your servers, you should be able to live without it. On the client desktop, you should be able to find a shortcut to the Windows PowerShell ISE. However, if you already have the PowerShell console open, then you can launch the ISE directly at the prompt:

PowerShell

1

PSC:>ise

If you are running your console elevated, then the ISE will also run in an elevated session. When I need the ISE, I never bother looking for the shortcut because I simply can start it from PowerShell. It’s even better that you can open files in the ISE directly from PowerShell.

PowerShell

1

PSC:>iseC:scriptsGet-HyperVEvents.ps1

Next, if you later run the following ISE command, then the file will be opened in a new tab in the currently-open ISE.

PowerShell

1

PSC:>iseC:scriptsSet-ComputerConfiguration.ps1

Note that this trick only works for a single PowerShell console. If you open a new PowerShell console and run an ISE command, then you will get a second instance of the ISE.

Pay close attention to this code sample. I don’t have a comma separated list of files, e.g. “file1.ps1,” “file2.ps1,” but rather one string with a comma separated list of files. If you wanted to open a number of files from PowerShell using the pipeline, then you would need something like this one line command:

PowerShell

1

2

PSC:>dirc:scriptsdev-win*|foreach-Begin{$list=@()}-Process{

$list+=$($_.fullname)}-end{ise"$($list -join ",")"}

That is a bit cumbersome, so I put together a short function that will achieve the same result.

PowerShell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

#requires -version 3.0

FunctionOpen-ISEFile{

<# .Synopsis Open a list of files in the PowerShell ISE. .Description This command is intended to take a directory listing of select files and open them all in the PowerShell ISE. .Example PS C:\> dir c:\scripts\dev-win* | open-isefile

#>

[cmdletbinding()]

Param(

[Parameter(Position=0,Mandatory,HelpMessage="Enter the path to a file",

ValueFromPipelinebyPropertyName)]

[ValidateScript({Test-Path$_})]

[string[]]$Fullname

)

Begin{

Write-Verbose"Initializing the list of files"

$list=@()

}

Process{

foreach($itemin$fullname){

Write-Verbose"Opening $item"

$list+=$($item)

}

}

End{

Write-Verbose"Opening files in the ISE"

ise"$($list -join ",")"

}

}#end function

As you can see in the help example, all you need to do is pipe your directory listing of files to Open-ISEFile.

The Windows PowerShell ISE Layout

One you have the ISE open, it is a pretty simple affair, where you type your code in the script pane and it executes in the command pane. More on that later. You can download the Open-ISEFile function here.

The PowerShell ISE, with the script pane at the top and the command pane at the bottom. (Image: Jeff Hicks)

A great feature of the PowerShell ISE is that you can select one or more sections of code, press F8 and the highlighted section will run. You can also run a single line of code this way. You don’t even need to select it all. If you press F8, then the ISE will run the line of code that contains your cursor. Or you can use the run selection menu icon as shown below.

Change the PowerShell ISE window layout

If the script pane is maximized, then the command pane is as well. I use the keyboard shortcut Ctrl+R to toggle between the two. This has become second nature that I try to use this shortcut in other applications as well! Another option is to use Ctrl+D to jump to the console pane and Ctrl+I to jump to the editor. Between all of these shortcuts I don’t spend a lot of time mousing around.

The PowerShell ISE has a great deal to offer the PowerShell scripter. I encourage you to learn the keyboard shortcuts you see on the menu items, for tasks that you use often. These tips should get you started down the path of working smarter and there is much, much more. I’ll be demonstrating more tips and tricks in future articles.

MEMBER LOGIN:

BECOME A PETRI MEMBER:

About the Contributor

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, teacher and consultant. Jeff has written for numerous online sites and print publications and is a frequent speaker at technology conferences and user groups. His latest book is PowerShell Scripting and Toolmaking.