Powershell Script to resolve alerts with specific alertname

I needed a script to resolve 30,000+ alerts with the same name and found this script below on the internet, I tweaked and changed the script somewhat and it resolves 30,000+ alerts in a matter of minutes.

I’ve tested this script on OpsMgr 2k7 R2 only.

param([string]$rms,[string]$alertName)

add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;

$mgConn = New-ManagementGroupConnection -connectionString:$rms;

if ( $mgConn -eq $null )
{
[String]::Format(“Failed to connect to RMS on ‘{0}'”,$rms);
return;
}

Set-Location “OperationsManagerMonitoring::”;
Set-Location $rms;

$criteria = [string]::Format(“Name = ‘{0}’ AND IsMonitorAlert = 0 AND ResolutionState < 255”,$alertName);

Get-Alert -Criteria $criteria | ForEach-Object {
    [String]::Format(“Closing Alert ‘{0}'”,$_.Name);
    $_ | Resolve-Alert -Comment “Closed by automation script” | out-null;   
}

 

To run, save the script as a .ps1 file, then use the following command:

.\script.ps1 –rms RmsName -alertName ‘Exact Alert Name’

The alertName is case sensitive.

This script will resolve all alerts that’s not created by a monitor.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s