Wednesday, December 20, 2017

#OpsMgr: Extract notification information

One of the areas of OpsMgr that often have the biggest impact on others is the notifications and many customers create a large number of notification subscriptions, which sometimes makes it hard to manage.

I created this PowerShell script to help a customer to extract notification information, covering channels, subscribers and subscriptions. The output of the script is an HTML file saved to the highlighted location


############################################################################
#
#   SCOM-NotificationConfigurationReport-htmlout.ps1
#
#   Script by: Vanessa Bruwer
#
#    This script retrieves all notification configurations and outputs as HTML file.
#
############################################################################

# Variables

$ReportDate = Get-Date -format "yyyy-M-dd"

$rnd = Get-Random -minimum 1 -maximum 1000
$ReportLocation = "C:\Temp"
$ReportName = "$ReportDate-$rnd-SCOM-NotificationConfiguration.html"
$SavetoFile = "$ReportLocation\$ReportName"


# there should be no need to update the script beyond this point

# Delete any previous versions of the report for in case

If (Test-Path $SavetoFile){
     Remove-Item $SavetoFile
}


# Open the content
$body = "<font face=Arial><table border=0><tr><td><b>Notification Configuration</b></td></tr><tr><td><font face=Arial>"


# Connect to OperationsManager

Import-Module OperationsManager

$MGName = (get-scommanagementgroup).Name

# Get Channels

$body += "<table border=1 bordercolor=silver width=100%><tr><td colspan=2><b>Channels</b></td></tr>"
$body += "<tr><td><b>Channel Display Name</b></td><td><b>Type</b></td></tr>"

$Channels = Get-SCOMNotificationChannel

foreach ($Channel in $Channels)
{

$ChannelName = $Channel.DisplayName
$ChannelType = $Channel.ChannelType

#Write-Host $ChannelName, $ChannelType

$body += "<tr><td>$ChannelName</td><td>$ChannelType</td></tr>"

}

$body += "</table>"

$body += "<p></p>"


# Get Subscribers

$body += "<table border=1 bordercolor=silver width=100%><tr><td colspan=2><b>Subscribers</b></td></tr>"
$body += "<tr><td><b>Display Name</b></td><td><b>Address Name</b></td></tr>"

$Subscribers = Get-SCOMNotificationSubscriber

foreach ($subscriber in $Subscribers)
{
$Subscribername = $subscriber.Name

$subscriberaddress = ($subscriber.devices).Name


#Write-Host $Subscribername, $subscriberaddress

$body += "<tr><td>$Subscribername</td><td>$subscriberaddress</td></tr>"

}

$body += "</table>"
$body += "<p></p>"


# Get Subscriptions

$body += "<table border=1 bordercolor=silver width=100%><tr><td colspan=4><b>Subscriptions</b></td></tr>"
$body += "<tr><td><b>Display Name</b></td><td><b>Description</b></td><td><b>Enabled</b></td><td><b>Recipients</b></td></tr>"

$subscriptions = Get-SCOMNotificationSubscription

foreach ($subscription in $subscriptions)
{

$subname = $subscription.DisplayName
$subdescription = $subscription.Description
$subEnabled = $subscription.Enabled
$subrecipients = ($subscription.ToRecipients).Name


#Write-Host $subname, $subdescription, $subEnabled, $subrecipients

$body += "<tr><td>$subname</td><td>$subdescription</td><td>$subEnabled</td><td>$subrecipients</td></tr>"
}

$body += "</table>"

$body += "</td></tr></table></font>"

$body >> $SavetoFile


This is a sample of what the output looks like from my lab environment:

notifications

No comments:

Related Posts with Thumbnails