Version 2.0 of My Script to Download All SCOM Management Packs with PowerShell

Not so long ago I’ve wrote a script that can download all SCOM Management Packs released by Microsoft. Unfortunately Microsoft has decided to change the interface of their download pages and didn’t asked me for approval Smile. Because of that the script stopped to work as it was dependent on the layout of the download web pages. I’ve decided to give it a try to fix the script. Looked at the layout of the new download page. Change a bit the logic and some lines and viola the script is working again.

You can grab Version 2.0 of the script from TechNet Gallery or from systemcentercentral.com.

P.S. The Script requires PowerShell 3.0.

Download All Microsoft Management Packs for SCOM 2007, R2 and 2012 in Bulk with PowerShell

Just last week Daniel Savage published a list on TechNet Wiki with all management packs for OpsMgr 2007, R2 and 2012. A couple of days later Stefan Stranger wrote Finding Management Packs from Microsoft Download website using PowerShell and provided a small PowerShell script that provides a list with the management packs from that site and links to them. After reading that post I was wondering wouldn’t be cool if you get the names of all management packs and their links and download all of them with their guides also. And when you download them to be able to organize them in structure that includes the name of the MP and its version. Instead of writing to Stefan I’ve said to myself – What the hell I will try to make that script. I do not have any big experience with PowerShell and it was not easy to built the script but because I’ve managed to create this proves that PowerShell is easy to learn but you have to be persistent. During the creation of the script I’ve noticed that some of the links on the page were incorrect so I’ve corrected them.

In short the script grabs the names and the links for all management packs on the site. Than it goes trough every MP link. From every MP page gets the version of it and all download links (msi, guides and etc.). Than creates a directory for that MP and subdirectory with the version number and downloads all files in it. The script requires PowerShell v3.

Here is the script:

   1: #Get list of all Management packs and their links from Technet Wiki

   2: #Thanks to Stefan Stranger http://blogs.technet.com/b/stefan_stranger/archive/2013/03/13/finding-management-packs-from-microsoft-download-website-using-powershell.aspx

   3: $allmpspage = Invoke-WebRequest -Uri "http://social.technet.microsoft.com/wiki/contents/articles/16174.microsoft-management-packs.aspx"

   4: $mpslist = $allmpspage.Links | Where-Object {($_.href -like "*http://www.microsoft.com/*download*") -and ($_.outerText -notlike "*Link to download page*") -and ($_.InnerHTML -like "*This link*")} |

   5: Select @{Label="Management Pack";Expression={$_.InnerText}}, @{Label="Download Link";Expression={$_.href}}

   6:

   7: #Directory to save the downloaded management packs. Make sure it is created first before running the script

   8: $dirmp = "D:\MPs\"

   9:

  10: #go trough every MP

  11: foreach ($mp in $mpslist)

  12: {

  13: #get MP link

  14: $mplink = $mp.'Download Link'

  15:

  16: #get MP name

  17: $mpname = $mp.'Management Pack'

  18: Write-Host "MP Name:" $mpname

  19: Write-Host "MP Link:" $mplink

  20:

  21: #Read MP page

  22: $mppage = Invoke-WebRequest -Uri "$mplink"

  23:

  24: #Find all download links on the page (mp, guide and etc.). $_.href cannot be used beacuse some of the links require conformation before download

  25: $dws = $mppage.Links | Where-Object {($_.'bi:fileurl' -like "*http://download.microsoft.com/download*") } | Select @{Label="Download Link";Expression={$_.'bi:fileurl'}}

  26:

  27: #Find the version number of the MP on its page

  28: $version = $mppage.ParsedHtml.getElementsByTagName("td") | Where "classname" -contains "col2" | Select -ExpandProperty InnerText

  29:

  30: #Remove character ? in fron of MP version. For some reason some versions of mps start with ?

  31: $version = $version.Replace("?","")

  32:

  33: #Remove / character from MP name if contains it beacuse can create unneeded directories

  34: $mpname = $mpname.Replace("/","")

  35: Write-Host "MP Version:" $version

  36: Write-Host "Download Links:" $dws

  37:

  38: #Create directory with the Name of the MP and subdirecotory with the version of the MP

  39: New-Item -ItemType directory -Path $dirmp\$mpname\$version

  40:

  41: #Get the array of found download links

  42: $dws = $dws.'Download Link'

  43:

  44: #Get trough every download link

  45: foreach ($dw in $dws)

  46: {

  47: #assign download link to $source variable

  48: $source = $dw

  49:

  50: #Get the name of the file that will be downloaded

  51: $Filename = [System.IO.Path]::GetFileName($source)

  52:

  53: #Set directory where the file to be downloaded

  54: $dest = "$dirmp\$mpname\$version\$Filename"

  55:

  56: #initiate client for download

  57: $wc = New-Object System.Net.WebClient

  58:

  59: #download the file and put it in the destination directory

  60: $wc.DownloadFile($source, $dest)

  61: }

  62:

  63: #empy line

  64: Write-Host

  65: }

You can download it from TechNet Gallery also.

Once again thanks to Stefan Stranger.

Reset SCOM Unit Monitors in Bulk with PowerShell

This is another great article by Pete Zerger that he teaches us how to leverage PowerShell for managing SCOM. Find the full guide here.

OpsMgr 2012: Disabling Rules and Monitors in Bulk in PowerShell

Another great article by Pete Zerger. In this article he give us an example how to leverage PowerShell to bulk disable or enable monitors and rules.

OpsMgr 2012: Running a Task in Bulk Using PowerShell

What to say more than: Another great and very useful article by Pete Zerger. Just read the full article here.