Using PowerShell to import/export management packs

In MOM 2000 and MOM 2005, Microsoft provided the ManagementModuleUtil tool as a means to import and export management packs in a batch mode. This tool no longer exists, but there are cmdlets in PowerShell that allow you to do just that.

Importing Management Packs using PowerShell

You can import a management pack with the install-managementpack cmdlet. The following example imports an information worker management pack that was included on the Operations Manager installation media. The syntax would be:
install-managementpack -filepath Z:\Microsoft.Informationworker.Commonlibrary.mp
You can put this in a batch file and import multiple MPs this way. The error checking provided by the Operations console import function is not available, but it can be a faster approach for a bulk import of management packs.

Exporting Management Packs using PowerShell

The export process is a little more interesting. Microsoft gives a syntax example that exports all unsealed management packs to the root of the C:\ drive:
$mps = get-managementpack | where-object ($ .Sealed -eq $false)
foreach($mp in $mps)
{
export-managementpack -managementpack $mp -path "C:\"
That’s nice, but you have to run this from within the OpsMgr Command Shell.
We can put that code in a batch script which you can run from the standard PowerShell environment per the following example. Be sure the path you will be exporting to already exists. You will also have to provide the name of the RMS as a parameter (or hardcode it in the script):
param ($ServerName)
add-psssnapin
"Microsoft.EnterpriseManagement.OperationsManager.Client":
set-location "OperationsManagerMonitoring::";
new-managementGroupConnection -ConnectionString:$ServerName;
set-location $ServerName;
 
$mps = get-managementpack | where-object ($ .Sealed -eq $false)
foreach($mp in $mps)
{
export-managementpack -managementpack $mp -path "C:\backups"
 
Save this in a file with a PS1 extension so it is executable by PowerShell. We’ll name our script file exportMP.ps1 and save it to a directory on the RMS named c:\Backups.
 
Now, the final step is to put this in a batch file. The batch file contains the following syntax:
%systemroot%\system32\windowspowershell\v1.0\powershell.exe c:\backups\exportMP.ps1 -ServerName:<rootmanagementserver> 
where you specify the name of the RMS for the <rootmanagementserver> parameter.
We can put this file also in our c:\backups directory on the RMS and it runs like a champ!
 
Other thoughts:
You can also export SEALED management packs, which the Operations console does not allow you to do. The following code will export all management packs, both sealed and unsealed:
$all_mps = get-managementpack
foreach($mp in $all_mps)
{
export-managementpack -managementpack $mp -path "C:\backups"
Thanks to Maarten Goet for providing us with this example.
 
You could also export only sealed mangement packs by changing the selection criteria in the first export example to ($ .Sealed -eq $true)
Why would you want to export sealed management packs – other than to look at them? To incorporate new reports you want to add to an existing management pack, for example. We write about this in more detail in our forthcoming book, System Center Operations Manager 2007 Unleashed.
Advertisements
This entry was posted in Operations Manager 2007. Bookmark the permalink.

7 Responses to Using PowerShell to import/export management packs

  1. Julius says:

    the syntax on the automatic script is wrong, it should be
     
    param ($ServerName)add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;set-location “OperationsManagerMonitoring::”;new-managementGroupConnection -ConnectionString:$serverName;set-location $ServerName;

  2. Operations says:

    Good catch! There was a blank space there that shouldn\’t have been. It has been corrected.

  3. Brent says:

    Try as I might I couldn\’t get this to work. I eventually found all the references to the same script were missing a crucial parameter. Here is the new script I have working:param ($ServerName)add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;set-location “OperationsManagerMonitoring::”;new-managementGroupConnection -ConnectionString:$serverName;set-location $ServerName;$mps = get-managementpack | where-object -filterscript{$_.Sealed -eq $false}foreach($mp in $mps){export-managementpack -managementpack $mp -path "C:\\CustomPacks"}

  4. Operations says:

    Hi Brent,Can you indicate the line that is different here? I\’ve compared the text above to yours and nothing is jumpingout as being different.

  5. Pingback: Cameron Fuller - Q&A Session for #SCOM 2012 - Critical Migration Considerations

  6. when i try $all_mps = get-managementpack command on scom 2007r2 , im getting error saying path parameter is empty or required location is not set .
    can someone help how to resolve this ?
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s