Inside Management Packs

Have you ever wondered how the Microsoft shipped management packs actually work? There are a couple of ways to look inside the Management Packs (MPs) and understand how they are actually working. Although you need a bit of PowerShell to get a glimpse inside the MPs, it’s worth a look…

Note: the code below only works on an Operations Manager 2012 installation – it will NOT work on SCOM 2007 (R2)!

Where are the Management Packs?

Well, in general, MPs are stored in the database as soon as they are imported but when you look at the ManagementPacks folder on the installation media you’ll see that all by default installed management packs are in this folder (and more).

All the management packs which are installed in your management group can be exported to readable XML easily by a little PowerShell cmd-let using the Operations Manager Shell:

Get-SCOMManagementPack | Export-SCOMManagementPack -Path c:SCOM_MPS_AS_XML

Make sure the path as specified above exists or use your own output path. After executing the command, all your installed management packs (sealed AND unsealed!) will show up in the directory as XML.

In case you are wondering why MS ships all by default installed MPs as MP with the installation media, you’ve probably not done any MP authoring/development yet. When you author your own MPs using various tools you need them as reference for modules.

There’s another way to get readable XML from MPs. This blog post from Pete Zerger demonstrates how to unseal MPs using the SDK only (without a live management group). The code from Pete runs on SCOM 2007 (R2) but will not run in SCOM 2012 because the SDK, mainly the location of classes and namespaces changed. Here’s a modified snippet which runs on SCOM 2012:

$assembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.Core") | out-null
$MPs = Get-ChildItem C:SC2012OMRTMManagementPacks -Recurse -Include *.mp
foreach ($mp in $MPs)
    $mgmtpack = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPack($mp)
    $mpWriter = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackXmlWriter("c:SCOM_MPS_AS_XML")

Note, that the assembly is a different one when you use the SCOM 2012 SDK, the rest is the same.

What’s inside the Management Packs?

With the above we managed to look deep inside the management packs and can now see how the shipped management packs are built and how they are working exactly. You can see, all the class definitions, discoveries, monitors, rules, views, folders, etc. For advanced authoring and development you can also see what modules Microsoft is using in their MPs. Modules are the basic building blocks for SCOM workflows. This is a great way to learn how to use certain modules. A complete list of documented and supported modules can be found here:

When you look at all the unsealed MPs you will realize that there are much more modules than the list MS is providing. You can of course also reference modules from management packs which are not in the list but keep in mind that MS may change the signature/parameterization of those modules and your MP may be screwed then. The list above is more or less a list with MS’ blessing and they try to keep them the way they are for compatibility reasons.

Wait, there’s more: Management Pack Bundles

With SCOM 2012, MS introduced a new packaging format for management packs called:Management Pack Bundles (.mpb files). Those of you who played around with Service Manager may already know about that. MS originally introduced bundles in Service Manager. It basically allows you to put resources like images or even assemblies in a management pack.Daniele Grandini and Stefan Stranger both blogged about that and provided a handy little script to dump the contents with all resources to the file system:

$inDir = "C:SC2012OMRTMManagementPacks"
$outDir = "C:SCOM_MPS_AS_XML"


$mpStore = New-Object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackFileStore($inDir)

#now dump MPB files
$mps = get-childitem $inDir *.mpb
$mpbReader = [Microsoft.EnterpriseManagement.Packaging.ManagementPackBundleFactory]::CreateBundleReader()
if ($mps -ne $null)
    foreach ($file in $mps)
        md ($outDir + ""+ $file)  #ADDED
        $mpWriter = new-object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackXmlWriter($outDir + ""+ $file)    #ADDED
        $mpb = $mpbReader.Read($file.FullName, $mpStore)
        foreach($mp in $mpb.ManagementPacks)
            #write the xml
            $streams = $mpb.GetStreams($mp)
            foreach($stream in $streams.Keys)
                $mpElement = $mp.FindManagementPackElementByName($stream)
                $fileName = $mpElement.FileName
                if ($fileName -eq $null)
                    $fileName = $outDir +'' + ($mp.Name)+ '.' + $stream+ '.bin'
                    If ($fileName.IndexOf('') -gt 0)
                        #only on dir level supported
                        $dir = $outDir + '' + $fileName.SubString(0, $fileName.IndexOf(''))
                        if ([System.Io.Directory]::Exists($dir) -ne $true)
                    #$fileName = "${outdir}${fileName}"
                    $fileName = $outdir+""+$file+"$filename" #ADDED
                Write-Host "`t$fileName"
                $fs = []::Create($fileName)

The above script is pretty much the same as Stefan Stranger’s script just without the unsealing MPs stuff (as we have covered this earlier).

That’s it for now. Happy hacking!

Leave a Reply