Powershell Quick Tips SCOM

Disable all alerts for a SCOM management pack using PowerShell

So use this wisely…

This script will use Out-Gridview to prompt the operator for the management pack to disable the alerts for and the override management pack to save those overrides in.

Enjoy!
Dan

First, the script to do this for all monitors:

Import-module operationsmanager

$SCOMServer = "<SCOMServerName>"
New-SCOMManagementGroupConnection -ComputerName $SCOMServer

$MPSource = get-scommanagementpack -ComputerName $SCOMServer | where {$_.Sealed -eq $True} | Out-GridView -Title "Select a single SOURCE Management Pack" -PassThru
$MPOverride = get-scommanagementpack -ComputerName $SCOMServer | where {$_.Sealed -eq $False} | Out-GridView -Title "Select a single TARGET Management Pack" -PassThru

Write-Host ""
Write-Host -ForegroundColor Red "!!!!!!! WARNING !!!!!!!"
Write-Host ""
Write-host "All Monitors in MP " $MPSource.Name "will have"
Write-Host "an override create that sets the Generate Alert value to False."
Write-Host ""
Write-Host "Overrides will be saved to" $MPOverride.name
Write-Host ""
Write-Host ""
$Proceed = Read-Host   "Type 'Apply' to continue"
If($Proceed -eq "Apply")
    {
    $Monitors=$MPSource|Get-SCOMMonitor -ComputerName $SCOMServer |?{$_.xmltag -eq "UnitMonitor"}
    ForEach($Monitor in $Monitors)
        {
        If($Monitor.AlertSettings.AlertOnState -ne $null)
            {
            $Target= Get-SCOMClass -ComputerName $SCOMServer -id $Monitor.Target.id
            $OverrideName=$Monitor.name+".Override"
            $Override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($MPOverride,$OverrideName)
            $Override.Monitor = $Monitor
            $Override.Property = "GenerateAlert"
            $Override.Value = "false"
            $Override.Context = $Target
            $Override.DisplayName = $OverrideName
            }
        }
    $MPOverride.Verify()
    $MPOverride.AcceptChanges() 
    Exit
    }
Else
    {
    Write-Host ""
    Write-Host "User aborted process"
    Write-Host ""
    pause
    Exit
    }

Second, the script to do this for all rules:

Import-module operationsmanager

$SCOMServer = "<SCOMServerName>"
New-SCOMManagementGroupConnection -ComputerName $SCOMServer

$MPSource = get-scommanagementpack -ComputerName $SCOMServer | where {$_.Sealed -eq $True} | Out-GridView -Title "Select a single SOURCE Management Pack" -PassThru
$MPOverride = get-scommanagementpack -ComputerName $SCOMServer | where {$_.Sealed -eq $False} | Out-GridView -Title "Select a single TARGET Management Pack" -PassThru

Write-Host ""
Write-Host -ForegroundColor Red "!!!!!!! WARNING !!!!!!!"
Write-Host ""
Write-host "All Rules in MP " $MPSource.Name "will have"
Write-Host "an override create that sets the Generate Alert value to False."
Write-Host ""
Write-Host "Overrides will be saved to" $MPOverride.name
Write-Host ""
Write-Host ""
$Proceed = Read-Host   "Type 'Apply' to continue"
If($Proceed -eq "Apply")
    {
    $Rules=$MPSource | Get-SCOMRule -ComputerName $SCOMServer | ?{$_.xmltag -eq "Rule"}
    ForEach($Rule in $Rules)
        {
        If($Rule.Enabled -ne 'True')
            {
            Disable-SCOMRule -Rule $Rule -ManagementPack $MPOverride
            }
        } 
    Exit
    }
Else
    {
    Write-Host ""
    Write-Host "User aborted process"
    Write-Host ""
    pause
    Exit
    }

Leave a Reply

Your email address will not be published. Required fields are marked *