Ezine 187 – PowerShell 2.0 ISE
The command line will always be at the heart of PowerShell. However, all scripting languages benefit from a GUI, or an Integrated Scripting Environment (ISE) as Microsoft describes this add-on console. If you merely use PowerShell to issue a few one-line commands then it’s probably not worth bothering with the ISE shell. But if you want to debug a block of code, or create and save .ps1 files, then the ISE will soon become your best friend.
PowerShell 2.0 ISE
- This Week’s Secret
- Getting Started with PowerShell’s ISE
- 5 Beginner’s Tips for Using PowerShell ISE
- PowerShell v 3.0
In truth I was disappointed when I first saw the ISE, but that was back with PowerShell 2.0 CTP2. However, in CTP3 the graphical interface is coming of age, and by the final release, ISE will be a tasty appetizer for the main course of PowerShell 2.0. For once it seems that a program’s flashy front-end, namely ISE, is the last feature that Microsoft implements, and not the first.
Assuming that you have successfully installed PowerShell 2.0, to launch the ISE click on the ‘Start’ button, navigate to All Programs, Windows PowerShell V2, and then simply click on Windows PowerShell ISE. Incidentally, the underlying executable is powershell_ise.exe so you could fire-up the ISE in the time honoured way of typing powershell_ise in the run box.
Getting to Know the ISE
PowerShell is a classic example of learning a feature in one area and then applying it elsewhere. For me it’s just a case of remembering this principle and applying it at every opportunity. For example, I love get-Member or gm for short. Then I discovered that PowerShell’s ISE has its own built-in variable $psIse. It came as a pleasant surprise when the instruction: $psIse | gm returned useful information.
$psIse | get-Member
# Next, remove hash from next line
Interesting, but what is the point you may ask? Well, try this: $psIse.options.scriptpanebackground ="Cyan". Now experiment with other settings to suit your style.
For instance, you can reposition the bottom Command Pane with:
$psIse.options.CommandPaneUp = 1 (or zero)
A Reminder of the ExecutionPolicy for Running Scripts
Be default, and for security, you cannot run any PowerShell scripts. Now before you change this setting try the ‘get’ verb to see the setting before your run set-ExecutionPolicy. To see the options try this: help set-ExecutionPolicy.
# Now try
As an aside, you can control the script behavior when you initialize a session by running PowerShell.exe with a -ExecutionPolicy parameter. However, I have not yet found a reason to operate this way, I prefer to make a lasting change with set-ExecutionPolicy.
Guy Recommends: The Free IP Address Tracker (IPAT)
Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets. IPAT cracks this problem of allocating IP addresses in networks in two ways:
For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges.
For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker
1) Select a Snippet
One advantage of the GUI is that you can select a block of code with the mouse, and click on the green arrow, which then runs that portion of your script. My point is that if you have a moderately long script you can highlight one part and run just that code snippet.
2) Find the Wiper!
If you look at the second pane of the ISE, then one tool stands out, and that’s the ‘Wiper’; its official tag is ‘Clear Output Pane’. As I was a great fan of the DOS cls (Clear screen), I love clicking on this tool to get a fresh screen.
3) New Tabs
This is so simple it seems hardly worth mentioning, but if you go to the file menu and click on ‘New’ you can easily access another script or window. I find these extra tabs useful for hopping between different versions of a script I am working on. As usual, Microsoft provide two ways of doing everything, there is a ‘New’ icon on the vertical toolbar.
4) Save Files
Once again, ‘File –> Save’ is pretty obvious, but for me this is a crucial reason for using the ISE rather than the raw command line. I make excessive use of saving scripts regularly, this to compensate for me not working methodically. I have learned from the hard school of knocks, in the past I have a script which is 95% complete, but then I do something silly and wreck it. If only I could go back to how it was 10 minutes ago. Well, if I saved a previous version with a different file name, then I can retrieve that stage of the script.
5) Debug Menu
By the time you explore the Debug menu, you are no longer a beginner. While my task of getting you started is over, I just want to reassure you that as you become more proficient at PowerShell, so ISE has powerful tools to correct any wayward code.
Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.
It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.
While the ISE is the last feature that Microsoft has developed in PowerShell v 2.0, it will probably be the first place you go when you start using PowerShell regularly. As with any utility it’s worth spending a few minutes investigating all the tools, and as usual the 80:20 rule applies, you will only use 20% of the features 80% of the time. Furthermore, each person uses a different 20%, so my greatest joy is if you experiment to see which ISE features suit your style of scripting.
If you like this page then please share it with your friends
See more Windows PowerShell tutorials
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.