An Advanced PowerShell HTML HotFix Report

powershell hero

Last time, I showed you a PowerShell script that leveraged my hotfix reporting function to create a basic HTML report complete with highlights and active links. The challenge I left for myself, or perhaps you worked on it yourself, was to display the page title for the hotfix online link. That way I can tell at a glance what problem the hotfix is solving. The difficulty, at least in my development efforts, is that target HTML document does not lend itself to the typical way I would approach this task with Invoke-WebRequest or Invoke-RestMethod. My solution was to resurrect a technique I used back in my VBScript days, and that is to use Internet Explorer.

This version of my reporting script includes the same features as last time so I won’t repeat that discussion. If you recall, the function output includes a URL. All I need to do is navigate Internet Explorer to that page and get the document title. This will require a COM object for Internet Explorer.

As each hot fix is enumerated I can search for the URL.

Now the fun part. I can tell the IE object to go to that page.

In my experience I have found it helpful to loop while Internet Explorer is busy, otherwise the script will continue with other steps I may not be ready for. After the page has been loaded, I can get the document title.

In my testing I discovered that sometimes the location took a little time to resolve so I added an additional loop. But once I have the title, I can insert it into the HTML table.

When I’m finished getting the titles, I can get rid of the IE object.

Now I have a very meaningful report.

an advanced HTML hotfix report
an advanced HTML hotfix report (Image Credit: Jeff Hicks)

As you can imagine, making all of these connections is a time consuming task. If you think about it for a moment, the same hotfix is very likely installed on multiple servers so it doesn’t make sense to keep checking. My solution to this is to create a hashtable. As each URL is resolved, the title is added to the hashtable.

With the hashtable I can check it first and if there is an entry use it instead of trying to resolve it online.

I also realized that the next time I run the script, assuming it’s a monthly report, there is bound to be some overlap. In other words, the report will show hotfixes that I’m showing in this report. So why not save the resolved hot fix links and re-use them? In my script I export the online links to an XML file in the same directory as the script.

If this file exists, I can import it to initialize the hashtable.

The end result is that the script runs much faster, at least after the very first time. The only online links that need to be resolved are the new ones.

And since I was revising the script to make it more advanced, I decided to add some parameter attributes and validation. I also realized that since my hotfix function supports alternate credentials, I should offer that option in this script and pass the credential on. I used splatting.

The end result is a script that anyone can run to generate a meaningful and useful HTML-based report.  Here is the complete script for your reference.

The script is written to work in my environment because it dot sources where I’m keeping my Get-MyHotfix function. You would need to change that. It is also importing a CSV file on my computer. You could create your own CSV file. Or perhaps you want to modify the function to take the computer names as parameter values. The last change you might want to make is to not use Write-Host as I am to display status messages and implement Write-Progress.

If you tried to write the last script first, you would most likely be frustrated and cursing PowerShell. Instead, I encourage you to follow the development process I’ve outlined over the course of several articles. I think you will find the process much more enjoyable and probably more educational.

I hope you’ll leave a comment and let me know what you think about all of this.

Related Topics:

  • PowerShell

    Don't have a login but want to join the conversation? Sign up for a Petri Account


    More Articles by Jeff Hicks