Thursday, July 4, 2013

OpsMgr 2012 - Subscriptions - selective enabling of subscriptions again

With most of the System Center Operations Manger (2012 and 2007) updates, you have to disable all the subscriptions and enabled them later again.
the examples are for 2012, but just delete the "SCOM" from the poweshell commands, and it should run in 2007.


So disabling of all subscriptions can be done with a one liner in powershell:

Get-SCOMNotificationSubscription | Where {$_.Enabled  -eq $True} | Disable-SCOMNotificationSubscription

however in our environment, we have a lot of subscription, and there is also a number disabled. so enabling all the proper subscriptions again is a painfull slow excercise.... but not anymore....

this simple poweshell creates a logfile with all the subscriptions and their state (so run it before you disable the subscriptions.....)

$log = "D:\Tools\Powershell\subscriptions.txt"
set-content $log ""
$pcs = Get-SCOMNotificationSubscription
foreach ($pc in $pcs)
{
    [string]$entry = $pc.displayname + "," + $pc.enabled
 add-content $log $entry
}


and now when you're done with your tasks, and you want to enable your subscriptions again:

$log = "D:\Tools\Powershell\subscriptions.txt"
$file = get-content $log
foreach ($line in $file)
{
    if ($line -ne "")
    {
        $pc = $line.split(",")
        if ($pc[1] -eq "True")
        {
            Get-SCOMNotificationSubscription -DisplayName $pc[0] |Enable-SCOMNotificationSubscription
        }
    }
}

the script is a bit slow, so it will run for 15 minutes or more, but you can do something else

Regards,
Andre

No comments:

Post a Comment