Thursday, December 15, 2016

Backup Unsealed OpsMan Management Packs

The best practice for SCOM when importing a new management pack is to create a new unsealed management pack.  I typically name it similarly with a suffix "_overrides".  I then put any overrides related to the rules or objects in the management pack in the unsealed management pack.  In our environment we have our devices monitored by two OpsMan environments - a test and a production  environment.  We install and tweak management packs in the test environment and when we are satisfied they are not too chatty, both the sealed and unsealed management packs are imported into production. 
I wanted to orchestrate the backup of these management packs so that any modifications would not be lost, so I wrote a script to find any unsealed management packs and export them to a unc path.  Here's the script:


<#
.SYNOPSIS – Backup management packs in a OpsMan 2012 Environment 

.DESCRIPTION – This script is run on a schedule and is used to backup unsealed SCOM Managementpacks.

.PARAMETER OpsManServer - FQDN of Operations Manager Management server

.PARAMETER BackupPath - UNC path to backup management packs

.PARAMETER OpsManCredential - PSCredential object for account with rights on OpsMan Server

#>
Param (

[string]$OpsManServer,

[string]$BackupPath,

[PScredential]$OpsManCredential

)

Try{

# Import OperationsManager module

Import-Module OperationsManager
    
# Open persistent connection to Operations Manager Management Server

New-SCOMManagementGroupConnection -ComputerName $OpsManServer -Credential $OpsManCredential | Set-SCOMManagementGroupConnection
    
# Get All unsealed MananagementPacks (assume these are custom)

$CustomMps = Get-SCOMManagementPack -ComputerName $OpsManServer -Credential $OpsManCredential | where {$_.sealed -eq $false} 

# Export each MP to the specified path 

ForEach ($CustomMP in $CustomMPs){
    
    Export-SCOMManagementPack -ManagementPack $CustomMP -path $BackupPath
    
    }
    
# Close Connection to OpsMan Server

Get-SCOMManagementGroupConnection | Remove-SCOMManagementGroupConnection 

}
Catch{
    
        Write-Error -Message "Failed to backup managment packs on $OpsManServer"

        Write-Error -Message $error
       
        $Result = "Failed to remove a SCOM Agent for $SCOMClientName from Managment Server $SCOMManagementServer"
}

$Result