Let me explain. The Integrated Scripting Environment (ISE) that comes with PowerShell v. 3.0 and above is great. It is a useful tool for PowerShell script developers who need an environment that will help them create scripts quickly. However, there are some features which you might see in other Integrated Development Environments (IDEs) that are missing from the PowerShell ISE. That’s where ISESteroids comes in.
ISESteroids adds many more features to the ISE. The best part is that it is simply a PowerShell module. Just import the module like you would any other PowerShell module, and you are up and running.
Below is a walkthrough of what I think are some of the most useful and most powerful features of ISESteroids.
- Variable renaming
- Script to function, function to module
- Find references, go to definition
- Function explorer
- Sign scripts
If you use a variable name multiple times throughout a script, it may be located throughout your script. If, for some reason, you decide that the variable should have a different name, it can be tricky to find and rename all of the occurrences of that variable. You do have the option of doing a find and replace on the whole document, but that may not be what you want. ISESteroids will perform a “smart” renaming of variables, taking into account the scope of the variable and any arguments if necessary.
Note: As of the time of this writing, ISESteroids is still in beta. As a result, the rename feature will sometimes rename variables out of the current scope or miss renaming referenced arguments. I expect that this will be fixed in the final version, and I will update this article accordingly, as things change.
Script to function, function to module
This one is just plain neat.
ISESteroids can take a snippet of code and transform it into a function, and from a function into a whole other module!
By simply highlighting a block of code and right-clicking that code, you can break out a block of code into its own function.
You will be prompted to name the function (using the PowerShell-approved verbs) and select which variables should become parameters of the new function. By leaving the checkbox at the bottom checked, your function will be created in a new script. If this is a quick transformation, you can also choose to create the function in place by unchecking that box.
And voila! Your snippet comes out as a valid function, complete with placeholders for documentation. You can see that the variables have been converted to parameters, and that the logic below is retained from the original snippet.
Now we can take it one step further. ISESteroids can take any function and bundle it into a PowerShell module. The module can be a new module, or an existing module (if the existing module was created with ISESteroids).
To export a function into a module, just right-click any existing function declaration and select “Export To Module” from the context menu.
Once again, you will be prompted with a dialog box with options for the function in this module. You have the option to either create a new module or add the function into an existing module. You also have the option to remove the code from its current location when you add it to the module (to simplify the script and externalize the logic). Once you have made your selections, click “Export” to create the new function as a member of your (new) module.
ISESteroids will add your function as a new function in the module, and create the module if necessary.
New modules will be created in your personal module directory (Documents\WindowPowerShell\Modules), with all of the requisite files and settings. It is up to you to change any properties of the module that you would like to update (author, company, etc.).
And there you have it. The module is created with your new function loaded into it.
All of this was made possible by ISESteroids. We took a simple snippet of code out of our script, made it into a function, and exported that function to a new module. It doesn’t get any simpler than this, ladies and gentlemen.
Find references, go to definition
Another neat feature is the ability to find references to a function or go to the definition of a function.
Above every function definition will be a counter that displays the number of references to the defined function in the script.
Clicking on the counter (if greater than zero) will display a list of all of the references in the script.
Clicking the reference will scroll the ISE script pane to the location of the reference.
Conversely, right-clicking a reference to a function anywhere in your script will allow you to navigate to the definition of that function.
It’s small, but can be quite helpful when dealing with a lengthy script.
Another small, but useful feature is the function browser that ISESteroids adds at the top of the script pane.
The function explorer lists all of the available functions in the script and allows you to quickly move between them.
ISESteroids includes the ability to easily sign your script with an existing code-signing certificate, one of my favorite features.
A new icon is added in the toolbar that allows you to control certificates and signing.
If you do not have a code signing certificate, when you choose to “Apply New Signature”, you will be prompted to create a self-signed certificate. You can also create one before-hand with the “Create Self-Signed Test Certificate” menu option. Later, you can remove the certificate by selecting the “Remove Self-Signed Test Certificate” option.
You will be prompted for the certificate name and validity period. Make sure that you choose to trust the certificate on this computer, otherwise you could see warnings about the certificate being invalid when you execute your PowerShell code.
Windows will display a warning because this is a self-signed certificate.
When you choose to sign the certificate, you will be given an option of which certificate you would like to use. In my case, I have the self-signed certificate that I just created and one that is generated by a trusted certification authority.
Finally, once the code is signed, you will see the code signing icon change to a solid red color, indicating that the code is signed and trusted. The menu options change also, allowing you to view the signer details, change, or remove the signature on the file.
My favorite part (as if all this wasn’t cool enough) is that when you save your script, the signature block at the bottom will automatically update for you! No need to remember to re-sign the script for every little change you make. ISESteroids makes sure that your code is signed with your selected signature each time you save. That alone is such a time saver if you’re using signed scripts.
If you are serious about PowerShell at all, this is a requirement for your arsenal. Get it, try it out, and let me know what you think in the comments below.