Export SCOM 2012 subscriptions subscribers and channels

Hi,

Below is a powershell script that will export all information for SCOM 2012 subscriptions.  You need to run the script in the OpsManager shell. The script creates a html file called out.html in c:\temp directory.  You can change

#Export Subscriptions

#Created by GLouw 2013 04 25

#Script exports all information including Subscribers, the Channel and even the criteria of the subscriptions in SCOM 2012 and SCOM 2012 SP1

 $subs = get-scomnotificationsubscription | Select-Object Id, DisplayName, Enabled, ToRecipients, Actions, Configuration

$FileLine = @()

foreach ($sub in $subs) {
     $ddd = $sub.Actions
     #write-host $ddd
     $recipientlist = “”
     $recipients = $sub.ToRecipients | Select-Object Name, Devices
     $groups = $sub.Configuration.MonitoringObjectGroupIds | Select-Object Guid, Name
     $classes = $sub.Configuration.MonitoringClassIds | Select-Object Guid, Name
     $criterias = $sub.Configuration.Criteria

   #write-host $criterias
   
   foreach ($recipient in $recipients) {
          $recipientlist += $recipient.Name + ‘(‘ + $recipient.Devices[0].Address + ‘) , ‘
    }
   $subgroups = “”

   foreach ($group in $groups) {
         $groupname = Get-SCOMGroup -Id $group.Guid | Select-Object DisplayName
         $subgroups += $groupname.DisplayName + ‘ ; ‘
   }

   foreach ($class in $classes) {
        write-host $class.Guid
        if (!$class.Guid) {
           $classname = Get-SCOMClass -Id $class.Guid | Select-Object DisplayName
           write-host $classname.DisplayName
          }
   }
   $actions = $sub.Actions |Select-Object From,Subject,Body,DisplayName,Description,EndPoint
         foreach ($action in $actions) {
            $out = New-Object -TypeName PSObject
            $saas = $action.Body
            #write-host $saas
     Add-Member -InputObject $out -Type noteproperty -Name Id -Value $($sub.Id)
     Add-Member -InputObject $out -Type noteproperty -Name SubscriptionName -Value $($sub.DisplayName)
            Add-Member -InputObject $out -Type noteproperty -Name SubscriptionCriteriaGroups -Value $subgroups
            Add-Member -InputObject $out -Type noteproperty -Name SubscriptionCriteria -Value $criterias
     Add-Member -InputObject $out -Type noteproperty -Name Enabled -Value $sub.Enabled
     Add-Member -InputObject $out -Type noteproperty -Name SubscriptionRecipients -Value $recipientlist
     Add-Member -InputObject $out -Type noteproperty -Name From -Value $action.From
     Add-Member -InputObject $out -Type noteproperty -Name Subject -Value $action.Subject
     Add-Member -InputObject $out -Type noteproperty -Name Body -Value $action.Body
     Add-Member -InputObject $out -Type noteproperty -Name SubscriptionChannel -Value $action.DisplayName
     Add-Member -InputObject $out -Type noteproperty -Name ChannelDescription -Value $action.Description
     Add-Member -InputObject $out -Type noteproperty -Name ChannelSMTPServer -Value $action.Endpoint.PrimaryServer.Address
     Add-Member -InputObject $out -Type noteproperty -Name ChannelAuthenticationType -Value $action.Endpoint.PrimaryServer.AuthenticationType
     Add-Member -InputObject $out -Type noteproperty -Name ChannelPortNumber -Value $action.EndPoint.PrimaryServer.PortNumber
     Add-Member -InputObject $out -Type noteproperty -Name SwitchBackPrimary -Value $action.EndPoint.PrimaryServer.PrimaryServerSwitchBackIntervalSeconds
     Add-Member -InputObject $out -Type noteproperty -Name SMTPEndPointDisplayname -Value $action.EndPoint.DisplayName
     Add-Member -InputObject $out -Type noteproperty -Name SMTPEnpointDescription -Value $action.EndPoint.Description
     Add-Member -InputObject $out -Type noteproperty -Name RecipientProtocol -Value $action.EndPoint.RecipientProtocol

            $FileLine += $out
          }
#            write-host $action.From
#            write-host $action.Subject
#            write-host $action.Body
#            write-host $action.DisplayName
#            write-host $action.Description

#            write-host $action.Endpoint.PrimaryServer.Address
#            write-host $action.Endpoint.PrimaryServer.AuthenticationType
#            write-host $action.Endpoint.PrimaryServer.PortNumber
#            write-host $action.Endpoint.SecondaryServers
#            write-host $action.Endpoint.PrimaryServerSwitchBackIntervalSeconds
 #           write-host $action.Endpoint.DisplayName
  #          write-host $action.Endpoint.Description
  #          write-host $action.Endpoint.RecipientProtocol
#     write-host $action.Endpoint
    }
Function Set-AlternatingRows {

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$True)]
        [string]$Line,
      
        [Parameter(Mandatory=$True)]
        [string]$CSSEvenClass,
      
        [Parameter(Mandatory=$True)]
        [string]$CSSOddClass
    )
 Begin {
  $ClassName = $CSSEvenClass
 }
 Process {
  If ($Line.Contains(“<tr>”))
  { $Line = $Line.Replace(“<tr>”,”<tr class=””$ClassName””>”)
   If ($ClassName -eq $CSSEvenClass)
   { $ClassName = $CSSOddClass
   }
   Else
   { $ClassName = $CSSEvenClass
   }
  }
  Return $Line
 }
}
$Header = @”
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
.odd  { background-color:#ffffff; }
.even { background-color:#dddddd; }
</style>
<title>
Title of my Report
</title>
“@
$Pre = “Heading before the report”
$Post = “Footer after the report”

$FileLine | ConvertTo-HTML -Head $Header -PreContent $Pre -PostContent $Post -Property Id,SubscriptionName,SubscriptionCriteriaGroups,SubscriptionCriteria,Enabled,Recipients,From,Subject,Body,SubscriptionChannel,ChannelDescription,ChannelSMTPServer, ChannelAuthenticationType,ChannelPortNumber,SwitchBackPrimary,SMTPEndPointDisplayName,SMTPEndPointDescription,RecipientProtocol |Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd |Out-File c:\temp\out.html

6 thoughts on “Export SCOM 2012 subscriptions subscribers and channels

  1. Nice script, and very helpful, but it only shows the first Notification Channel when more than one is defined in the subscription.

  2. This script looks awesome. But I am getting an error when I run it: Any ideas?

    The string starting:
    At C:\sub.ps1:110 char:12
    + $Header = <<<< @"
    is missing the terminator: "@.
    At C:\sub.ps1:126 char:1
    + <<<<
    + CategoryInfo : ParserError: (
    TABL…temp\out.html
    :String) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

  3. Very helpfull script, BUT not show group and classes.
    Use scrip from SCOM 2012 R2.
    How can i get subscriptions with criteria classes ?

  4. There is guid.
    Name is empty.

  5. Hey man, congratulation! very good script mate… It just what I was trying to do it

Leave a reply to Eugene Leitan Cancel reply