Greg Shultz takes a look at Commands add-on and Snippets, two of his favorite new features in Windows 8.1 PowerShell ISE.
During this last week, I've been working on a PowerShell script that will search through the Windows Event logs for particular words or phrases — something that you can't do in Event Viewer using Filters or Custom views. While I started working on the script using just Windows 8.1's PowerShell Console, I soon switched over to the PowerShell Integrated Scripting Environment or PowerShell ISE.
I had used the PowerShell ISE in Windows 7 (PowerShell ISE 2.0) but not Windows 8 or Windows 8.1 (PowerShell ISE 3.0 and 4.0 respectively). Needless to say, I was very surprised at all of the new features introduced in 3.0 and carried over to 4.0. The user interface is more refined and easier to use, plus there are a ton of new features. I'm still mastering these new features, but I've discovered that creating the testing PowerShell scripts is a whole lot easier in PowerShell ISE 4.0.
There are two new features, in particular, that I found extremely helpful: the Commands add-on and the Snippets feature. Let's take a look.
With support for add-ons, you have the ability to extend the PowerShell ISE with additional tools created by Microsoft and third-parties. To showcase the add-on feature, Microsoft created and included the Commands add-on, which allows you to browse cmdlets and access help about the cmdlets from within the ISE while viewing the Script and Console panes at the same time (Figure A).
The Commands add-on feature.
As you can see, you can access and control the position of add-ons using two buttons on the toolbar — one that opens an add-on in a pane on the right and one that opens the add-on in a separate window. You can use more than one add-on at a time, as additional add-ons will appear on separate tabs. You'll find a separate Add-ons menu that provides you with commands for accessing, repositioning, and hiding the Add-ons pane. There is also a command that accesses Microsoft's Add-on Tools Website, where you can find and download even more add-ons created by others.
The Commands add-on is an awesome feature. Not only does it provide you with a complete list of all PowerShell commands, but you can filter by Module to make it easier to find what you're looking for, select an individual command, and see a description of that command (Figure B).
You can filter by Module and access a description of a particular command.
Clicking the Show Details button will display the command's parameters along with text boxes into which you can enter the parameters you want to use. You can then click the Run button to test your command in the Console pane. You can click the Copy button to copy the command, complete with the parameters, into the Clipboard, and then paste the command into the Script pane. If you need additional information on the command, simply click the Help icon (Figure C).
Using the Show Details and Help are great features to have on hand when creating a script.
Snippets are short sections of PowerShell code that you can instantly insert into your scripts. This feature will save you both time and effort when it comes to coding your PowerShell projects. By default, PowerShell ISE 4.0 comes with a nice set of generic snippets, but you can create and add your own code snippets into the PowerShell ISE system using the New-IseSnippet cmdlet.
You can access the Snippets feature from the Edit menu by selecting the Start Snippets command or by using the [Ctrl]+[J] keyboard shortcut. When you do, you'll see a pop-up window from which you can select the snippet you want to use (Figure D). As you scroll though the available snippet names, hover over one, and you'll see the code it contains. Just click on the name, and you can insert the code into the Console pane or the Script pane. You can then fill in the details however you see fit.
You can select the snippet that you want to use from the pop-up window that appears when you access the Start Snippets command.
Creating your own snippets out of code that you regularly use will save you both time and effort. To do so, simply access the New-IseSnippet cmdlet in the Commands pane, fill in the details, and click Run. When you do, your snippet will be added to the Snippets pop-up window (Figure E), where you can easily access it anytime you need it.
Using the New-IseSnippet cmdlet in the Commands pane makes it easy to create your own custom snippets.
As I mentioned, PowerShell ISE 4.0 in Windows 8.1 is packed with new features — the Commands Add-on and Snippets are only two of my favorites. Of course, I could go on and on about all the new features in PowerShell ISE, but I'll come back to it in future articles and discuss some of them. For now, you can explore PowerShell ISE 4.0 on your own (just use [Windows]+[S] to find PowerShell ISE) and peruse the What's New in the Windows PowerShell ISE page on Microsoft's website.
What's your take?
Have you already investigated PowerShell ISE 4.0 in Windows 8.1? If so, what are your favorite new features? If you haven't yet used PowerShell ISE 4.0 in Windows 8.1, has this article prompted you to do so? As always, if you have comments or information to share about this topic, please take a moment to join in the discussion thread below.