Giving the PowerShell ISE a major upgrade
Time for something a bit different in this post. I do most of my PowerShell script development in the built-in ISE. It’s clean, uncluttered and what it does, it does well. It is of course, also very basic. I have in the past tried a couple of other free development environments and just felt no draw to them at all after a brief try. So, until now I’ve remained stuck using the standard Microsoft offering.
Recently, I read a blog post about a module for ISE that provides a major power-up – “ISE Steroids”. Its 2nd version is currently in a frequently-updated preview form and that’s what I’ve been playing with. Being a module for the existing ISE means you feel instantly at home in it since it’s enhancing the existing interface and it can, if desired, just be activated on an as-and-when basis. Don’t let the word “module” make you think this is a relatively minor addition like Microsoft’s “Script Browser/Analyzer”. This really is the ISE on steroids … and not just a small sneaky dose of anabolic steroids either; this beast would get the ISE banned from athletics for life. The author is Dr Tobias Weltner. If you like PowerShell but don’t know that name, then you ought to. He has produced an indispensable set of “PowerTips” PDFs which can be found at powershell.com or on his own website. I strongly recommend them to you.
After unblocking the downloaded ZIP file, installation is like unzipping any other module into a folder in your PSModulePath. You then activate it within the ISE by running the command Start-Steroids. Here is the normal ISE toolbar:
And here is the view – after using the Start-Steroids command:
You could of course get it to auto-start by adding the command to your ISE profile script. There’s an icon on the toolbar to get at that easily – it’s the little green-shirted man on the right. Note that in the above screenshot I had also clicked the Settings icon on the far right and that caused the extra tab of options to slide into view in a rather slick fashion.
A quick note on that extra tab of options; they enable highlighting of minor and major code style issues (eg strings in double-quotes), highlighting matching braces (very useful!). They also provide optional auto-completion of quotes, brackets and braces.
The first main row of icons starts off looking familiar but includes a “Blank Script from Template” button so you could make yourself some generic starter script layouts. The section for starting and stopping the script includes a nifty button of a red bug for managing breakpoints.
Next to it, the button that in the normal ISE merely opens a PowerShell window has been replaced with something far more useful. A right-click shows you all the possibilities that will enable thorough testing to be much easier. This will be invaluable in an enterprise environment.
Next along is the familiar group of buttons for different layouts. An extra has been added to the end and I love it. It’s called “Script Pane Maximized and External Console”. When you click it, the script pane maximises and the console pane detaches into a separate window:
As you can see, this floating window looks rather cool. It has a short toolbar with a button to stop the script if it’s running; a pin button to keep it on-top; and a third (toggle) button that makes the underlying script window disappear altogether. You’ll notice both this console window and the script window have an overlayed transparent icon in their bottom right corners. Clicking either of these switches you to the other window of the pair effortlessly. It’s really very slick. If you close the floating console window, you’re returned to the usual dual-pane view in the ISE.
The last section of icons on the top row of the enhanced ISE toolbar are for various add-ons which I’ll come to later.
The second toolbar row (which can be hidden) has features that affect the behaviour of the ISE and how your code is displayed. I’ll pick out a few. The first button is for automatically aligning the indentation of braces. It defaults to two spaces but you can adjust this. There’s no excuse for sloppy formatting now (a pet hate)!
A related option which you’ll see in use in my earlier screenshots is “Toggle visible whitespace” which is like the feature in Word that shows paragraph markers, tabs and spaces etc. There’s also a word-wrap button. I’ll be using both of these all the time.
Other buttons affect what is highlighted – eg just the line or the current language element. Here’s an example from the latter showing an entire Try-Catch block being outlined when the cursor is on the try keyword. As you can see, the effect is quite subtle.
Related to this is an AutoSelect button which when clicked repeatedly, highlights and selects progressively bigger chunks of code from the cursor position – ie parent code blocks. In the above example, you’d get the Try-Catch block followed by the If script block, followed by the entire If construct, followed by the foreach script block and finally the entire foreach construct. I personally think this will prove most useful for visually checking the relationship of nested code blocks and the associated flow of script logic.
If like me, you like to collapse sections of code to focus your attention, there are some buttons to do this – eg for comment blocks, the current code region, and 1st and 2nd levels of outlining. I do this sort of thing all the time in Notepad++ with VBScript so this will be really useful here as I’ve found sections tend to uncollapse all the time in the standard ISE. There’s also an Expand All Outlining button.
The far-right of the second toolbar row has icons for printing and creating XPS files and a button that pops up the help text for the selected Cmdlet in a window. Also there is an icon for a beefed-up Snippet Manager:
Have you ever typed something into the console pane to test and then had to copy the line and paste it into your script pane? There’s now a toolbar button to do this for you in one click!
Struggling to find areas in a long script? There is a button for adding Bookmarks (inside a comment) which can then be navigated to from a section at the bottom of the script pane:
At the far end of the toolbar is an icon that enables a Script Map. This appears as a strip down the side of the window showing a very zoomed-out view of your code. The section currently visible in the editor window is highlighted, and by hovering with your mouse over the map, you can see the code at that point (ie find your way around) and then click to go to that position:
I think these last two features will make script navigation much easier.
I’ve saved some of the best to last. The far-right of the top toolbar has a number of different features that can optionally appear in a tabbed sidebar. One of these you’ll know from the normal ISE, is the Commands Add-On. Well, I hope you know it as it shows you modules with their commands and then lets you complete the parameters using textboxes, checkboxes and drop-down lists.
Next to it is the Variable Monitor Add-On. This is useful if you’ve set breakpoints, to see what is happening to the variables in your code. Here’s a screenshot of it in action – I left the Commands tab on too:
The next Add-On in the sidebar is the Context Sensitive Help. This gives attractively-formatted help in a sidebar with examples. The output can be made pageable or scrollable and there is a zoom slider for the text:
Next up is a snippet Autocompletion Tool followed by a Refactoring Tool. This latter tool which runs in Basic or Advanced mode helps format your scripts for you:
Here’s a very simple example. Before:
Advanced mode lets you choose exactly which reformatting procedures are performed against your code. They’re divided into categories. Here’s a taster of the ones in the Command category:
I suspect this is a feature that will continue to improve in its ability and accuracy as it has more and more scripts thrown at it. I tend to be quite fussy over my code layout already.
I’ve saved perhaps the best add-on until last. The last feature is File Version History and it is really quite powerful! You simply click a button to add a new version and you can choose between major and minor versions as shown below:
Version history is then shown in the sidebar and you can add Notes to each using the links, open old versions and compare versions. I’ve redacted where it shows computername/domain\Username.
You can classify each version as shown below:
The versioning works by creating a zip file containing the older versions alongside the main file along with an XML index file. In an enterprise environment especially, this feature will be indispensable.
So there you have it. Even in its current beta, this development environment is excellent!