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
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
