A Favorite PowerShell ISE Feature: Script Analyzer

Summary: Sean Kearney introduces a free tool for examining your script.

Honorary Scripting Guy, Sean Kearney, is here. This week I’m going to introduce you to my favorite Windows PowerShell ISE features.

   Note   This is a five-part series that includes the following posts about features in the Windows PowerShell ISE:

Today, I’m talking about a free add-on called the Script Analyzer.

In the past, I’ve written some scripts that literally “just worked,” but I still wondered if there was something I missed. More recently I wrote a couple of modules for the PowerShell Gallery. A requirement before uploading them was to run them through the Script Analyzer.

“What’s the Script Analyzer?” I asked myself as I scratched the few hairs on my head. “I don’t see a Script Analyzer anywhere.”

As it turns out, it’s a free add-on to the PowerShell ISE that allows you to scan through your script or module and get you as close to best practices as possible. It’s also incredibly easy-to-use.

To get this add-on, simply launch the PowerShell ISE, click Add-ons, and select Get Script Analyzer Add-on Tool from the menu.

Image of menu

This will launch your browser to download and install the actual tool.

Image of menu

When you download and install this tool, you’ll get not one, but two cool new features. The Script Analyzer and the Script Browser. I’ll talk about the Script Browser tomorrow.

When it is installed, you can access the Script Analyzer from the Tools menu on the right side of the ISE. If you don’t see it, restart the PowerShell ISE and press Alt+Shift+V at least once to ensure the Add-on tools menu is displayed.

It’s also very easy-to-use. Select a script or module you’re working on in the ISE. Here’s one called Untitled as an example:

Image of script

I then click the Scan Script button and wait a few seconds (or maybe a minute). The time is dependent on the size and complexity of your script or module.

 Image of menu

When the scan completes, it presents results and suggestions. This scan detected a couple minor issues:

Image of results

This does not mean your script is garbage or doesn’t work. It is simply making suggestions based on best practices. I can immediately double-click a line number and it will take me to the issue in question. For a new user of the Script Analyzer, the problem is that it doesn’t explain what that error means. For that, I click the little gear icon to view the options.

This brings up a menu of all the types of items that the Script Analyzer is looking for and why.

Image of menu

Clicking the rule presents a detailed explanation of why it’s being trapped. So again, it’s not an error so much as it’s being flagged as “not quite a best practice.” If this was a vendor script that has been digitally signed and you wanted to ignore a particular rule, you can clear that check box and re-scan the script.

As you can see in the previous image, there is a link called Suggest a new Script Analyzer Rule that you can use if you see something it’s not trapping you think it should be.

If I click Cancel and go back to the script, I can edit the line in question.

Image of script

Running a new scan will either identify further issues or reveal that all is good.

Image of message

It’s not a perfect solution. There are many things it still misses (for example, unreferenced variables and lack of Help for cmdlets). But it is a decent and free solution from Microsoft to get you going in your scripting quest.

Stop by tomorrow when I’ll take a look at the other add-on we downloaded, the Script Browser in the ISE.

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, always remember that with great PowerShell comes great responsibility.

Sean Kearney, Honorary Scripting Guy, Cloud and Datacenter Management MVP

Comments (14)

  1. Harm Veenstra says:

    I would suggest using ISESteroids as plugin, can do so much more

  2. @Harm Veenstra

    You are correct, ISESteroids is a far more powerful tool but it costs money. The goal is to show you what you have that is readily available and at no cost. It is by no means the BEST tool, but it’s a decent tool that you can leverage directly from Microsoft.

    Honorary Scripting Guy

  3. ML49448 says:

    When I click on Add-Ons, I only have the option to go to the Add-Ons Website. Am I missing something else?

  4. @Michael

    An error on my part. If you are running PowerShell 5 you should see this

    Honorary Scripting Guy

  5. The sharepoint is like 2 say 2 1 dr u r away 4 long mayb u r busy or wt.? i dn no y n never u answer me.

  6. POWashell says:

    If you are not using PowerShell 5 you can download the Script Analyzer add-in here

  7. @POWashell

    Great tip! Thanks for sharing!

    Honorary Scripting Guy

  8. Tim says:

    I don’t see that menu option at all.
    Is there a specific version of powershell 5 I have to be using? Because according to $PSVersionTable

    PSVersion 5.0.10586.0

  9. Tim says:

    Can’t Edit but here is the update: Even in powershell 5, you must go into View and make sure Show Command Add-on is checked in order to get the option.

  10. Matt5150 says:

    I can install Module Browser using the “Get Module Browser Add-on Tool” from the Add-ons menu in ISE. But the other two take me to a Microsoft error page, as do all the links I can find.

    Once I open the Module Browser, if I click the “Accept” button to let ISE install NuGet, I get and error of “Initialization failed. Unable to find package provider ‘NuGet’.”

    I downloaded PackageManagement_x64.msi, but when I launch that from Windows 10 x64, I get an error that .NET 4.5x and WMF 3.0+ is needed, leading to believe this is not for WMF 5.0.

  11. The link used by the ISE tool of (https://www.microsoft.com/en-ca/download/details.aspx?id=42525) no longer works. Can you provide any insights?

    1. cashcat1 says:

      me too, and none response to the question.

    2. Don Cole says:

      Both the Script Browser and the Script Analyzer Add-On links in Windows 10 ISE are broken. Looks like Microsoft has moved on from PowerShell already. Wonder what’s next?

  12. Suzanne says:

    I found one page that states that Script Analyzer and Script Browser are no longer available as of June 2016. No word as to why or if they’re being replaced.

Skip to main content