Powershell Script to Close Alerts older than a specified number of days and generated by Rules

Below is a script to close all Alerts that are older than a specified number of days that have been generated by rules. You can change the number of days to suit your requirements.

NOTE:-You won’t need to add the Opsmgr snap-in if you are already running the OpsMgr Command Shell.

# Load snapin and connect to RMS
# Remember to enter the fqdn name of the RMS below!
$RMS = “enter.fqdn.name.here
Add-PSSnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”
Set-Location “OperationsManagerMonitoring::”
New-ManagementGroupConnection -ConnectionString:$RMS
Set-Location $RMS
# Adjust the amount of hours to your liking, by default it is set at 96 hours.
$AgeHours = 96 
# Find alerts with New state which were created by a rule.
# This will close alerts older than the specified amount of hours if coming from a rule.
get-alert -criteria ‘ResolutionState=”0” AND IsMonitorAlert=”False”’ |where {$_.LastModified -le (Get-Date).addhours(-$AgeHours)} | resolve-alert -comment “Close old alerts generated by rules” | out-null
#end of script

This entry was posted in Powershell for SCOM and tagged , , , , , , , . Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s