Lately I have been enjoying learning the PowerShell scripting language for .NET; I don’t know why I waited so long! In this “PowerShell Primer” series I’ll try to pass along some of the tips & tricks I’ve learned along the way.
As with most scripting and programming languages, you can write PowerShell code with nothing but a bare-bones text editor like Notepad. Me, I tend to use one text editor (such as Notepad++ or Cream/VIM) for most daily work, but sometimes programming in a specific language is easier if you use a GUI IDE that really knows the language. In this article, I will cover two of them made just for PowerShell.
The ISE (Integrated Scripting Environment) is a handy text editor with essential IDE/scripting features. It has three panes–code editing, command entry, and output—allowing you to easily explore, get help, and test your script all in one place (much like Python’s IDLE). Also a lot of the language’s debugging features are available from within the ISE.
One big advantage of the ISE is that it’s included, more-or-less, with your PowerShell 2.0 installation (again, like IDLE is bundled with Python installations). On Windows 7, after installing PowerShell 2.0 you should find it buried in the Start Menu under All Programs | Accessories | Windows PowerShell (or just start typing in the Start Menu search, which I find the fastest). On Server 2008 R2, the ISE is installed as a “Feature” in Server Manager (or shortcut from the PowerShell prompt:
Import-Module ServerManager; Add-WindowsFeature PowerShell-ISE).
The ISE, however, is for the most part “bare bones”, without a lot of fancy features. Here are a few modules you can add on which include some very handy additional features:
- ISEPack (from the PowerShellPack, which was released as part of the Windows 7 Resource Kit) includes some great shortcuts for getting help on the highlighted word(s), searching through available objects, and more.
- Oising’s ISESessionTools includes commands to save and restore your open tabs, autosave the scripts in edit mode, and (my favorite) reloading the PowerShell command session (which you will probably want if you’re building a script with custom .NET objects added with
Add-Type, for example, because the session is not automatically reset when you re-run the script).
Quest Software’s PowerGUI is a full-featured IDE for PowerShell. Admittedly, it’s GUIness is great for some tasks, such as using the Administrative Console to browse and filter your Active Directory objects and getting the script to output just your selections—but I don’t use it for much day-to-day work because it’s slow to start and loaded with features I don’t use. Of course, some people may want just that: plenty of features in the Script Editor and even more downloadable add-on “PowerPacks”.
Note that to install PowerGUI you first need Quest’s PowerShell Commands for Active Directory, which are a solid improvement over the PowerShell core features for AD anyway. Also, you should know that PowerGUI is a “freemium”-style product, with the core features available free for all, and the premium features available at cost under the name PowerGUI Pro. So far, I haven’t found anything I needed that wasn’t in the free version, but that may change as I use PS more daily.