Every SCOM or SCSM specialists knows that backing up custom management packs is one of the most important tasks. Andrew Barton provides a PowerShell script for Service Manager for this task in Partner and Customer Solutions Blog.
Category: PowerShell
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.
PowerShell Script to Retrieve Performance Data from SCOM
SCOM 2012 doesn’t offer cmdlet that retrieves performance data but a script made from Brian Wren offers that. The script has several parameters that can be used but you can download and find more about the script directly from MSFT TechNet Gallery.
Documentation: Windows PowerShell Language Specification Version 3.0
Specification for PowerShell 3.0 is available for download in a form of docx file.
Windows Server 2012 Upgrade Jump Start Training
This Jump Start Training was held live last month and now it is available as a recordings. This course is led by Microsoft Senior Technical Evangelist Rick Claus and Ed Liberman from TrainSignal. The course is divided in 12 topics which can be found as separate videos here.