PowerShell script to automatically close old alerts in System Center Operations Manager

The PowerShell script in this article can help clean up some System Center Operations Manager environments with old alerts that are still active.

Original product version:   System Center 2016 Operations Manager, System Center 2012 R2 Operations Manager
Original KB number:   4464212

Script

The script can be used to automatically close old Operations Manager alerts. This script looks for active alerts along with the time when alert was created (alert age). If the alert age is greater than the specified number of days ($alertsTobeClosedBefore), the script will close the alert.

$alertsTobeClosedBefore = 5
$currentDate = Get-Date
Get-SCOMAlert | Where-Object {(($_.ResolutionState -ne 255) -and (($currentDate - $_.TimeRaised).TotalDays -ge $alertsTobeClosedBefore))} |Resolve-SCOMAlert