SCOM Close alerts from rules

Update: I placed the SCOM scripts related to this on Github. There is a script for 2007 and a script for 2012. The 2012 script will work for higher SCOM versions as well.

Was looking at a SCOM console with a lot of alerts today at a customer site. I did not feel like going through it all, so I wanted to clean out all alerts created by a rule, which had not been modified for at least 24 hours. This is because alerts coming from rules will not auto-close like the ones from monitors generally do.
So had to create a one-liner for it B)
This is for SCOM 2007.

get-alert -criteria ‘ResolutionState=”0” AND IsMonitorAlert=”False”’ |where {$_.LastModified -le (Get-Date).addhours(-24)} | resolve-alert -comment “Close old alerts generated by rules” | out-null

This will look for alerts with a New resolution state and coming from a rule, where the last modification to this alert was more than 24 hours ago, and close that alert with a small comment.
I have posted an extended script on Github at GitHub – BCornelissen/SCOMCloseAlerts: Scripts to help close alerts in SCOM coming from Rules
Sure cleaned out hundreds of old alerts :>

Allways comes in handy.
Bob Cornelissen