Cloning OpsMgr Notification Subs with PowerShell: 2012 R2 Edition

The following is the latest version of my script for cloning notification subscriptions in System Center Operations Manager 2012 R2.

The critical components to copy, all of which are hanlded by this script, are:

  • Group Filters
  • Class Filters
  • Criteria (severity, priority and other details…everything else basically)

You’ll also need to copy:

  • Notification Channel (this sample assumes you’re using SMTP)
  • Recipients (this example assumes only To: recipients, but cc: and bcc: would be very easy to add with the sample below)
Function CloneOMSub($SourceSubName, $TargetSubName) {
 
#Connect to the SCOM 2012 Server 
$ScomServer = 'mmsscom01'
Import-Module OperationsManager
New-SCOMManagementGroupConnection -ComputerName $ScomServer
 
#----------------------------------------------------
# Clone parameters from the existing subscription: 
# Recipients, Class Filters, Group Filters, Criteria 
#----------------------------------------------------
 
$TemplateSub = Get-SCOMNotificationSubscription -DisplayName $SourceSubName
$TemplateToRecipients = $TemplateSub.ToRecipients
$TemplateCriteria = $TemplateSub.Configuration.Criteria
$TemplateClassTargets = $TemplateSub.Configuration.MonitoringClassIds | select `
-ExpandProperty Guid
$TemplateGroupTargets = $TemplateSub.Configuration.MonitoringObjectGroupIds | select `
-ExpandProperty Guid
$TemplateChannel = $TemplateSub.Actions | select -ExpandProperty DisplayName
 
#Retrieve SMTP Channel used by existing subscription
$Channel = Get-SCOMNotificationChannel -DisplayName $TemplateChannel
 
#Create new subscription 
Add-SCOMNotificationSubscription -Name $TargetSubName -Channel $Channel -Subscriber `
$TemplateToRecipients -Criteria $TemplateCriteria
 
#Retrieve new subscription and update with Class and Group Targets
$NewSubscription = Get-SCOMNotificationSubscription -DisplayName $TargetSubName
$NewSubscription.Configuration.MonitoringClassIds.Add( $TemplateClassTargets )
$NewSubscription.Configuration.MonitoringObjectGroupIds.Add( $TemplateGroupTargets )
$NewSubscription.Update() 
}

You have to call the function with a single line of code right below the function itself in the script. It is worth noting that I found behavior to be pretty inconsistent when I used subscriptions with spaces in the name.

SYNTAX:

The script requires two arguments, the display name of the source subscription followed by the display name of the target copy.

CloneSub <SourceSubscription> <TargetSubscription>

For example:

CloneOMSub "Critical_SQL_Alerts" "SQL_Escalation_Sub"

Questions or comments? Use the comments section below.

Print Friendly, PDF & Email
Posted in Blog

Leave a Reply

%d bloggers like this: