Tuesday 23 June 2015

ISESteroids – An essential tool for PowerShell



Unless you’ve been hiding under a large log for the last few years, most of you who are responsible for administering windows have heard of PowerShell – Microsoft’s extensible scripting language designed to eventually replace all of its previous scripting environments for administrative tasks (such as vbscript, batch files etc.).  As I came into support from software development, I tended to use VB/VBScript or Perl to do any server scripting that I had to do, but as times have changed, so has PowerShell, to the point where not only has it become incredibly feature rich, but it’s now almost mandatory to use for certain deployments (hello Exchange 2013).  Over the last year, I’ve had to start using PowerShell almost daily, and so I started looking for a development environment to help me become more productive.

PowerShell comes with a quite good environment out of the box, called the Integrated Scripting Environment (ISE).  This little beauty allows you to write and debug PowerShell scripts, but I’ve always thought it was a bit clunky – especially if you’re used to Visual Studio / VB.  It was while I was looking for some PowerShell examples that I came across a fantastic add-on for PowerShell ISE that’s I’d like to share with you called ISESteroids…

ISESteroids is written by PowerShell guru Dr. Tobias Weltner, and it transforms the default PowerShell ISE environment into a PowerShell editing powerhouse!  It empowers and educates the PowerShell developer in the same way that Visual Studio did for Basic/C++ developers back in the day.  Allow me to elucidate further…

All the things that I love about Visual Studio / VB6 are here – context sensitive highlighting, auto-completion, context-sensitive help, combined with a rich debugging environment.  But that’s just for starters – there’s so much more, so here are a few of my favourite bits…

Better context sensitive help

ISE comes with its own context sensitive help – highlight a keyword, press F1 and you’ll get something like this…



That’s all well and good, but if you’re a PowerShell novice, some examples would be nice.  If you press ALT & F1 together though…



Isn’t that SO much better?  Not only that, but this help is also available as an additional tab in the add-ons window…



Peachy!

Real time search
 
Searching through code is always tedious, but ISESteroids real time search / function navigator option makes it less painful. The real time search bar is located at the top right of the editor window.   Enter your text, and the frame turns either red (if no matches) or green (matches found).  Every time you press RETURN, your cursor moves to the next match, SHIFT & ENTER moves you to the previous match.  When you’ve found a match, if you press F2, all the matches are highlighted & selected – you can then simply replace ALL of the matches just by entering your replacement text!

Bookmarks

Perhaps my favourite feature of ISESteroids is bookmarking.  When you’re working with long sections of code, it’s handy to be able to find a particular piece quickly.  Pressing CTRL & F7 in your code inserts a temporary bookmark on that code line – pressing it again removes the bookmark.  You can then move between book marks by pressing F7.  These bookmarks are remembered, so when you next open the file, they are still there.
There is however, a more permanent bookmarking feature which uses a custom comment.  If you insert <#bookmark text#> this is treated by ISESteroids as a permanent bookmark.  If you then press the Bookmarking menu button, you’ll get a bookmarking window with the current permanent bookmarks listed – you can then just click on them to move to that point in the code.  The bookmarking window can be pinned so it’s always available.


Code Snippets

Wouldn’t it be nice if you could enter in commonly used code at the touch of a button – well you can with code snippets?  This sort of feature is well known in other coding environments, and now you can have it in PowerShell. You can enter a code snippet in one of three ways: you can enter its shortcut (F4 gives you the entire list of shortcuts…)



Or you can press CTRL & J, which gives you an intellisense like dropdown of snippets you can navigate…



Or you can right click the editor, and select the “start snippets menu option, which gives you yet another way of inserting a snippet…



But even better than that, ISESteroids lets you create your own snippets with the snippet manager.  Once Open , you go through some basic steps (like where to save your snippet, and what you want to call the snippet...





At which point, you come to the actual snippet editor itself - which also includes it's own instructions on how to create your snippet. 



I followed these instructions and created a snippet that allowed me to create a permanent bookmark... 



Autorefactor

When you’re learning any new programming language, you’ll hit problems with semantics or idiosyncrasies that language has.  ISESteroids includes a lovely tool called the Autorefractor – it’s essentially a PowerShell clean-up / code correcting tool.  Here’s a piece of bad code… :)



You can see that on the left hand bar, there are small lightbulbs – each one of these is a problem that the Autorefractor has identified.  Most of the ones in the code above are double quotes I’ve used incorrectly.  If I click on the lightbulbs, the Autorefractor will correct these entries for me like so…



See how it’s corrected the quotes?  It’s also corrected a couple of lines where I was using a PowerShell alias (cd) to Set-Location!

Editor console flip

This is so useful.  I prefer giving myself as much coding space as I can, but sometimes you need to use the console window.  Usually, it’s a case of split screening the window so that the console window is visible (see the images above), but is there a better way – yup, the console flip…



Here’s the same editor window as before, but this time, I’ve maximized the editor pane.  What if I need the console?  Well, see the PowerShell icon in the bottom right?  Look what happens if I click it…



The console pane has now taken the place of the editor window.  I can get back by clicking on the Window icon on the bottom left of the pane…

What you can't really get a sense of from these screengrabs is how easy all this tools are to use, and how useful they actually are.  The best way to test it is to try it out yourself , or take a look at some of the videos available on the powertheshell website.  If I can get a few moments, I'll create a quick youtube video highlighting the areas I really like!

In summary, if you do ANY programming in PowerShell, ISESteroids should be at the top of your shopping list – it’s too damn useful..  :)



No comments: