Prof. Powershell
ISE, ISE, Baby
Cringe-worthy pun notwithstanding, PowerShell 2.0's Integrated Scripting Environment adds a cool new dimension to writing scripts.
- By Jeffery Hicks
- 03/15/2010
The graphical Powershell in 2.0, also known as the Integrated Scripting Environment, is a terrific tool that you should become familiar with. If you can't afford a more full-featured script editor, then at least use the ISE editor instead of NotePad to create PowerShell scripts. This time, let me show you a few tips on getting the most from the ISE editor.
First, while you can click icon and file menus (it is graphical after all), I still like keeping my hands on the keyboard in the command panel. Often I want to edit an existing script. The command-line way is to use the ISE PowerShell object and add the file this way:
$psISE.CurrentPowerShellTab.Files.Add("c:\scripts\tree.ps1")
Or, you can start a new script by not specifying a file:
$psISE.CurrentPowerShellTab.Files.Add()
That's a lot to type and I'll likely forget the exact syntax, so I put together a function (download here) that will load any file. I can either specify a file name or pipe file names to the function.
When you load a script, focus automatically jumps to the editor panel. As long as we're keeping our hands on the keyboard, you can press the F5 key to run the script. If you've modified it, the ISE editor will prompt you to save the file first.
I also like that I can highlight a section of script by pressing and holding the Shift key, then using the arrow keys to select a block. Just as cool is pressing F8 to run just the highlighted block of PowerShell. This feature comes in handy when you want to test small sections of your script or function.
When you're finished, press Ctrl+F4 to close the script window. If you want to jump back to the command pane, use Ctrl+D. The Ctrl+I combo will jump you back to the script editor.
There are plenty of other goodies with the ISE, but I'll save those for another day.
About the Author
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, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.