OpsMgr 2012 – how to dump management pack bundles (small “improvement”)

OpsMgr 2012 – how to dump management pack bundles (small “improvement”)

  • Comments 4
  • Likes

Last week Daniele Grandini posted a great PowerShell script to dump the contents of Management Pack Bundles (.mpb) files and the old MP contents.

The script takes 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.

Today I finally had some time to play with OM12 and PowerShell for a session I’m preparing and I also tried to Daniele’s dump management pack bundles PowerShell script. It worked as expected, but the results of the dumped mpb files where stored in the same directory together with all other dumped mpb file contents. And this is not what I wanted.

image

 

I would rather have the contents of each dumped mpb file stored in it’s own folder. That way it’s easier to explore the contents of the mpb file IMO.

So I made some small changes to the PowerShell script Daniele created to have each mpb file dump it’s content in it’s own folder.

image

Now it’s easier to see what has been dumped for each mpb file.

I hope Daniele won’t mind me changing his script slightly to fit my personal preferences Smile 

Here is my changed version of Daniele’s script:

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)
    {
        md ($outDir + "\"+ $file)  #ADDED     
        $mpWriter = new-object Microsoft.EnterpriseManagement.Configuration.IO.ManagementPackXmlWriter($outDir + "\"+ $file) #ADDED
        $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)
    {
        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
            $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}"
                    $fileName = $outdir+"\"+$file+"\$filename" #ADDED
                }
                Write-Host "`t$fileName"
                $fs = [system.io.file]::Create($fileName)
                $streams[$stream].WriteTo($fs)
                $fs.Close()
            }
        }
    }
}

 

See the comment # for what I changed.

 

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • I want to duplicate what you've done in C# code using the SCOM 2012 SDK methods.

    I've installed the SCOM 2012 console on my system. I had been told by Microsoft that this was what was needed to install the SDK assemblies on my machine.

    I use the object browser in Visual Studio to look at the Microsoft.EnterpriseManagement.Packaging namespace.

    I can find no ManagementPackBundleFactory class defined, only classes defined are:

    - ManagementPackBundle

    - ManagementPackBundleStreamSignature

    - ManagementPackReader

    - ManagementPackWriter

    So why does your sample powershell code have access to a Microsoft.EnterpriseManagement.Packaging.ManagementPackBundleFactory class - and on my system this class does not exist?

    Did Microsoft provide an extended alternative version of the assembly other than what is distributed with the SCOM 2012 RTM release that I need to find and install?

  • <p>

    &nbsp;</p>

    <p>

    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 ...

  • Hey there, I have created a small GUI app with C# and Visual Studio to unseal and unbundle management packs, inspired by the work done here. It's available at http://stevesbog.loungent.com/2014/03/04/a-gui-tool-for-unsealing-management-packs-and-bundles-in-scom/

  • Steve,
    Thanks for creating a GUI!

    /Stefan