Importing the SCOM PowerShell module
Import-module OperationsManager
#Connect to localhost when running on the management server
$connect = New-SCOMManagementGroupConnection –ComputerName localhost
# Or enable the two lines below and of course enter the FQDN of the management server in the first line.
#$MS = "
enter.fqdn.name.here"
#$connect = New-SCOMManagementGroupConnection –ComputerName $MS
# 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, after adding a comment.
get-scomalert -criteria 'ResolutionState=''0'' AND IsMonitorAlert=''False''' |where {$_.LastModified -le (Get-Date).addhours(-$AgeHours)} | resolve-SCOMAlert -Comment 'Close old alerts generated by rules' -PassThru | Set-SCOMAlert -ResolutionState 255
#end of script