Ezine 187 - PowerShell 2.0 ISEEzine 187 - PowerShell 2.0 ISEThe 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 ISEThis Week's SecretIn 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. Getting Started with PowerShell's ISEAssuming 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
Note 1:
Note 2: 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. get-ExcecutionPolicy get-ExcecutionPolicy # Now try set-ExecutionPolicy remotesigned 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. 5 Beginner's Tips for Using PowerShell ISE1) 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. If you are looking for handy network utilities, try some of the free downloads at Tools4Ever Summary of Microsoft PowerShell v 2.0 ISEWhile the ISE is the last feature that Microsoft have 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. See more PowerShell examples for syntax• PowerShell Home • Syntax • ISE (GUI) • Pipeline • Format-table • Group • Sort Please write in if you see errors of any kind. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.
*
| ||||||