Cloning Notification Subscriptions in Operations Manager 2012 using PowerShell [sample script]

Recently I received the same request for about the 100th time this week, so I thought I would quickly address the question:

“Can I copy a notification subscription in Operations Manager 2012”

This is an common question from people who want to create multiple copies in order to implement alert aging for notification escalation. They may want 3 copies of the subscription so they can adjust the alert aging setting on the copy to support alert escalation.

The good news is the answer is yes you can, even complex. This can be done with PowerShell using the Operations Manager 2012 cmdlets. In order to do this, you need to understand what you need to capture in order to copy the subscription. The critical components to copy 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)

Sample Source Subscription

I’ll use the following subscription named “Critical_SQL_Alerts” as an example, which contains all of these elements…not a basic subscription at all.

image

Now, we’ll look at how to copy this subscription using PowerShell so we can quickly and easily implement a notification escalation scheme.

Sample Script for Cloning Notifications

Here is a PowerShell function that requires only two parameters – the name of the source notification subscription to copy and the name for the target subscription to create. You may notice that I had to retrieve group filters, class filters and then all other criteria separately, which is why I called them out separately above.

NOTE: Make sure you update the value of the $ScomServer variable on line 2 with the name of one of your management servers.Next, we’ll look at how to call the function.

Calling the Function

You have to call the function with a single line of code right below the function itself in the script.

IMPORANT: 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:

Bringing it all together

Here is the full script with the function call beneath it. Just change the name of the source and target, bearing in mind the warning above about spaces in the name. I replaced spaces with the underscore (_) in the subscription names my tests and found behavior very consistent.

Additional Resources

You’ll find a growing number of System Center, Cloud and PowerShell resources here on SCC in the “Master Collection of System Center PowerShell” and elsewhere. A few related Operations Manager 2012 Command Shell articles

OpsMgr 2012: All my Java apps require manual discovery – where do I get BeanSpy and PowerShell install scripts?

OpsMgr 2012: Reset Unit Monitors in Bulk with PowerShell

OpsMgr 2012: Find Computers without the Active Directory Helper Object (OOMADS) with PowerShell

OpsMgr 2012: Disabling Rules and Monitors in Bulk in PowerShell

OpsMgr 2012: Group Maintenance Mode via PowerShell (the way it should be)

OpsMgr 2012: Running a Task in Bulk Using PowerShell

OpsMgr 2012: Automating Agent Discovery and Deployment with PowerShell [sample script]

OpsMgr 2012: Identifying Computers in Active Directory without an OpsMgr Agent Installed [sample script]

OpsMgr 2012 Quick Tip: Finding servers experiencing the most heartbeat failures with PowerShell

2 thoughts on “Cloning Notification Subscriptions in Operations Manager 2012 using PowerShell [sample script]

  1. Timothy Carroll

    Replace Get-SCOMNotificationSubscription -DisplayName $SourceSubName with the following line and it will work better.

    Get-SCOMNotificationSubscription | Where { $_.DisplayName -eq $SourceSubName }

  2. Timothy Carroll

    Actually I found more issues and fixed the “name with spaces” problem.  I’m pasting my modified version below.

    Function CloneSub($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

    #—————————————————-

     

    Import-Module OperationsManager

    New-SCOMManagementGroupConnection -ComputerName $ScomServer

     

    $TemplateSub = Get-SCOMNotificationSubscription | Where { $_.DisplayName -eq $SourceSubName }

    $TemplateToRecipients = $TemplateSub.ToRecipients

    $TemplateDescription = $TemplateSub.Description

    $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 | Where { $_.DisplayName -eq $TemplateChannel }

     

    #Create new subscription

    Add-SCOMNotificationSubscription -Name “Subscription$([Guid]::NewGuid().ToString().Replace(“-“,”_”))” -DisplayName $TargetSubName -Description $TemplateDescription -Channel $Channel -Subscriber $TemplateToRecipients -Criteria $TemplateCriteria

     

    #Retrieve new subscription and update with Class and Group Targets

    $NewSubscription = Get-SCOMNotificationSubscription  | Where { $_.DisplayName -eq $TargetSubName }

    ForEach ($target in $TemplateClassTargets) { $NewSubscription.Configuration.MonitoringClassIds.Add($target) }

    ForEach ($target in $TemplateGroupTargets) { $NewSubscription.Configuration.MonitoringObjectGroupIds.Add($target) }

    $NewSubscription.Update()

     

     

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.