OpsMgr 2012 – how to dump management pack bundles


With the release date of System Center 2012 getting closer, we’re upgrading our tools to the new version. As it always happens for new products, even if documentation is going to be good, it will not be enough especially for advanced topics. With Management Pack development this is especially true- Since the first way to understand new techniques is learning from others, or if you want via reverse engineering, one of the first steps to achieve this is to get access to MP contents and indeed we had several scripts in the community to do this . With Operations Manager 2012, a new format for MPs has been introduced: Management Pack Bundles (.mpb files). Actually Service manager had MPBs since a long time. The old scripts to dump the content of an MP file need to be updated to dump MPB as well.

With this post I’m going to share an handy powershell script that will allow to dump of both MP and MPB files for both OpsMgr and Service Manager. The script will take just two parameters an input directory where you have to copy MP and MPB files and an output directory where the dumps will be saved. The OpsMgr 2012 admin console needs to be installed for the script to work  properly.

You can find the script here:  https://www.sugarsync.com/pf/D6284134_0813286_659567

param($inDir, $outDir)

[Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.Core")
[Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.Packaging")

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

$mps = get-childitem $inDir *.mp
$mpWriter = new-object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackXmlWriter($outDir)
if ($mps -ne $null)
{
    foreach ($file in $mps)
    {
        $MPFilePath = $file.FullName
        $mp = new-object Microsoft.EnterpriseManagement.Configuration.ManagementPack($MPFilePath)
        Write-Host $file
        $mpWriter.WriteManagementPack($mp)
    }
}
#now dump MPB files
$mps = get-childitem $inDir *.mpb
$mpbReader = [Microsoft.EnterpriseManagement.Packaging.ManagementPackBundleFactory]::CreateBundleReader()
if ($mps -ne $null)
{
    foreach ($file in $mps)
    {
        $mpb = $mpbReader.Read($file.FullName, $mpStore)
        foreach($mp in $mpb.ManagementPacks)
        {
            #write the xml
            $mpWriter.WriteManagementPack($mp)
            $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’
                }
                else
                {
                    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)
                        {
                            [System.Io.Directory]::CreateDirectory($dir)
                        }
                    }
                    $fileName = "${outdir}\${fileName}"
                }
                Write-Host "`t$fileName"
                $fs = [system.io.file]::Create($fileName)
                $streams[$stream].WriteTo($fs)
                $fs.Close()
            }
        }
    }
}

 

– Daniele

This posting is provided "AS IS" with no warranties, and confers no rights.

  1. #1 by Stefan Stranger on March 6, 2012 - 4:18 pm

    Hi Daniele,

    Thanks for sharing this great script to dump the contents of the MPB files. To fit my personal preferences I made some small changes to your script. Hope you don’t mind. If so let me know and I’ll remove it from my blog.

    For the changes see my blogpost: http://blogs.technet.com/b/stefan_stranger/archive/2012/03/06/opsmgr-2012-how-to-dump-management-pack-bundles-small-improvement.aspx

    /Stefan

    • #2 by Daniele Grandini on March 6, 2012 - 5:58 pm

      Hi Stefan,
      this is a great example of community contribution. Thanks for reading my blog and sharing your improvements.

      – Daniele

  1. Inside Management Packs – code4ward.net
  2. Inside Management Packs | code4ward.net
  3. Inside Management Packs | code4ward.net
  4. Fixing missing stored proecdures for dashboards in the datawarehouse | Jan's System Center Blog
  5. Silect MP Studio 5.1 – First look at the new MPB support | smct GmbH
  6. Article d’Alban MONTANERA sur la compatibilité des packs d’administration - WebLog de Stéphane PAPP [MSFT] - Site Home - MSDN Blogs

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.