Monday, February 7, 2011

SCOM: Find Notification Subscriptions for Subscriber

What to do when you want to delete a subscriber in SCOM, but you can't because get an error like this:

The notification recipient is subscribed to at least one notification subscription.
Please remove it from all notification subscriptions before deleting it.
.....cannot be deleted as its currently in use.


To solve this you would have to browse manually through all your notification subscriptions. But how much time would that take.
With this PowerShell script it takes 2 seconds!

Get-NotificationSubscription | foreach {
$ns = $_.DisplayName
$_.ToRecipients | foreach {
If ($_.Name -match "John") {
Write-Host $ns
}
}
}

9 reacties:

John Bradshaw said...

Hi Michiel,
Thx for the above script.
I do not use Powershell normally, so I'm wondering if u can help please.
When I save this script as a PS1 file and run in OpsMgr Powershell (Windows 2008 R2), the script just goes back to the prompt. I do not see any output.

How do I see what is happening and make it run?
Thx,
John Bradshaw

Michiel Wouters said...

Hi John,

The script above only returns Notification Subscriptions for subscribers that match "John" :). Change this value to a value that matches a username that is listed under Administration \ Notification \ Subscribers.

You can also return all Notification Subscriptions with it's subscribers with the code beneath:

Get-NotificationSubscription | foreach {
Write-Host "---"$_.DisplayName"---"
$_.ToRecipients | foreach {
Write-Host $_.Name
}
}

Dominique said...

Hi Michiel,

I do not see any output even after changing "John" to "Dominique" should it be a subscriber or a member of the subscriber group?
Thanks,
DOm

Dominique said...

Hello,
I tried also to replace "John" by 'DOminique' single quotes or "Subscription8fb681b2_4ce7_4e7a_b01d_a83f670d8bb2" or 'Subscription8fb681b2_4ce7_4e7a_b01d_a83f670d8bb2' still nothing...
Any idea?
Thanks,
Dom

Michiel Wouters said...

Hi Dom,

The script should work. Please check if the Name of the Subscriber actually contains "DOminique".

You could check this by listing all subscribers with the command 'Get-NotificationSubscriber'

If you use the Operations Console and the OM Shell on different workstations and/or with different language settings then verify the Subscriber Name with those different settings.

The reason behind this .Net Culture detection. If you use English settings, any changes to the Subscriber Name are saved in the English Language Pack of the management pack for Notifications. If you then use, e.g. French, and retrieve the Subscriber Name you'll see the difference.

James Inderson said...

Please some more details and notification code.

mass notifications

John Bradshaw said...

Hi Michiel,
I did find that a snapin needed to be loaded before the scripts, for SCOM2007R2
e.g.

$Server = “myRMSserver.domain”
Add-PSSnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”
Set-Location “OperationsManagerMonitoring::”
New-ManagementGroupConnection –ConnectionString $Server
Set-location $Server

John Bradshaw said...

Hi Michiel,
Just another query if I may.
In SCOM you can set up a subscriber, but underneath this one subscriber may be many individual emails.
Is it possible to do a search on both Subscribers and Subscriptions for an individual email address?
Thx,
John Bradshaw

TommyGun said...

I wrote a small script to find all subscribers that are not part of a subscription.

Feel free to enhance the script.

---------------------------------

$subscriptions = get-scomnotificationsubscription

$configs = @()

foreach ($s in $subscriptions) {
foreach ($r in $s.ToRecipients) {

if ($r.Name) {

$config = New-Object PSObject

$config | Add-Member -type NoteProperty -Name 'Subscription' -Value "$($s.DisplayName)"
$config | Add-Member -type NoteProperty -Name 'Subscriber' -Value "$($r.Name)"

$configs += $config

}
}
}

$usedSubscribers = ($configs.Subscriber | Sort-Object | Get-Unique)

$allSubscribers = Get-SCOMNotificationSubscriber

$results = @()

foreach ($a in $allSubscribers) {
if ($usedSubscribers -notcontains $a.Name) {
$results += "$($a.Name)"
}
}

$result = $results | Sort-Object

---------------------------------

Post a Comment