OpsMgr 2012: Import Multiple Custom Management Packs with PowerShell

Hi all! Just wanted to share a small snippet that allows you to import multiple MPs into OpsMgr using PowerShell.

Some info about my working environment:

SPLOSCOM01- OpsMgr 2012 SP1 Management Server (UR3 applied)
SPLOBU01 - Backup Server

The script is rather basic...it loops through my MP backup directory on my backup server and imports each MP it finds into OpsMgr and echoes the MP it’s importing.

There are some caveats to this script...it does not check for dependencies and I only wrote it to import my custom MPs since I do a lot of builds and teardowns in my lab.

So, that being the case, here's the snippet:

Code Start------[

$filepath = "\\splobu01\Backups\ManagementPacks\Custom"
$mps = Get-ChildItem -Path "\\splobu01\Backups\ManagementPacks\Custom"
foreach ($mp in $mps) {
     Import-SCOMManagementPack -ManagementPack $filepath'\'$mp -ComputerName SPLOSCOM01
     Write-Host $mp
                                      }

]------Code Stop 

If you’re like me and like using the PowerShell ISE you’ll either need to import the following modules or edit your PowerShell profile to load the OpsMgr modules upon startup.

 
Code Start------[

Import-Module OperationsManager
Import-Module "C:\Program Files\System Center 2012\Operations Manager\Console\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1"
Import-Module "C:\Program Files\System Center 2012\Operations Manager\Console\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1"

]------Code Stop

 

You can check and see the imported MPs in the Operations Console or by running the following PowerShell Command

Code Start------[

Get-SCOM-ManagementPack | ?{$_.Name -like "test*"}

]------Code Stop

For the sake of this blog, I prefixed my MPs with the word "Test". The "?" is short for the Where-Object command and the asterisk is a wildcard, so it's searching for any MP where the name starts with "test". The output will look similar to this:

 

Thanks for reading!

Chris