FIXED: Get-SCOMManagementPacks.ps1

If you are unfamiliar with this script, it automatically downloads the Microsoft Management Packs and their Guides for Operations Manager in nice folders. Not sure how many people use this script or not, but I have noticed an increasing trend “null” error for a while. So I figured I would dig deeper into this and see if I could resolve the errors.


Related URLs:

Original Git Repo: https://github.com/slavizh/Get-SCOMManagementPacks

v4 Git Repo: https://github.com/gabrieljtaylor/Get-SCOMManagementPacks

Stanislav's blog post: https://cloudadministrator.wordpress.com/2014/08/26/version-3-0-of-damians-and-my-script-to-download-all-scom-management-packs-with-powershell/

Damian Flynn's blog post: https://www.damianflynn.com/2014/08/26/downloading-scom-management-packs-using-powershell/

Technet Gallery post (v3.0.1): https://gallery.technet.microsoft.com/scriptcenter/All-Management-Packs-for-37d37902

Stefan Stranger's blog post which started it all: https://blogs.technet.com/b/stefan_stranger/archive/2013/03/13/finding-management-packs-from-microsoft-download-website-using-powershell.aspx


What is the Issue?

When the PowerShell script is executed, majority of the management packs error out and output the following error.

image

It is complaining about a “null” value, which both the “Version” and the “Published” lines showing absolutely nothing. when you go to the download pages, both are listed.


Troubleshooting

So I started to debug the PowerShell script and try to find out where the breakdown was located. Working from the line 479 I was able to trace it all the way back to line ‘256’. The script ‘$HTTPData’, kept returning a false/null value. So taking the ‘$URI’ value I was able to validate the Management Pack download page was correct and working.

image

I started to debug the page and located the “Version:”, right away I noticed that the ‘</span>’ was no longer part of the page.

image

So then I removed the ‘</span>’ from the script and encountered no change in error when I ran the script. Frustrating!!!

Essentially it should be working, so then I wanted to dig a little deeper to see exactly what the “PageData” is showing. I debugged and placed my breakpoint at line 267, then ran the script; when it stopped, I typed ‘$HTTPData.PageData | clip’ and pasted it to notepad for a deeper look in what exactly is it showing.

image

I found for the “Version:” and “Published:”, and look at that, I saw that there were a lot of white-spaces between “Version:” and the “</div> as well as the “Published:” line. I copied all of the spaces and inserted it into the script. When the script ran, it worked, the pages that had the “null” error no longer did and the ones that didn’t have the issue now do. So what’s different? they must be older pages that have not been updated to the newer format maybe.

image

I then I backed tracked and looked at one that now was broke. They still have the ‘</span>’ in the “PageData”

image

so I placed the original  ‘$HTTPData’ lines with the ‘</span>’ below like so.

image

Ran the script once more out of debug mode of course, all the errors were gone with the exception of one, which I address later on.

Not enjoying all the spaces in the two ‘$HTTPData’ lines, I wanted to fix this since in the future who knows if a space(s) will be removed or added, in turn breaking again.

Let’s fix it now…

I found the expression I need to match the white-spaces, but when I applied it, I got the errors again.

image

So the next thing I added was a wildcard ‘*’ after the ‘\s’, so it looks like this now. Wasn’t even sure that the “*” would even work.

image

Now when I run the PowerShell script it works beautifully!

image

So just make these changes to your scripts and you’ll be fine.

I can’t update the GitHub script, so hopefully it will get updated soon.

You’ll be able to get it here: https://github.com/slavizh/Get-SCOMManagementPacks


Known Issue:

BizTalk Server 2013 R2 will continue to error out due to an “invalid” date, since the format is different that all the other management packs. but it should still download, however, I did not test this.

BizTalk Server 2013 R2                   7.0.2008.0                02/19/2015

image


So there you go.

Comments