MOM 2005: VB Script to close open alerts x days old
I did not do an extensive search to see if this had already been done, so I just slapped this together from what someone else did and added what I needed to it. Check out Jonathan Almquist's blog at http://blogs.technet.com/jonathanalmquist/default.aspx , the script I borrowed from him is documented in the script.
My modification gets the UTC date and time from one day ago, and closes any alerts whose TimeLastModified is older than that date and time.
'==========================================================================
' NAME: Scott Moss
' DATE : 4/20/08
' http://myitforum.com/cs2/blogs/smoss/default.aspx
' I modified an existing script MOM 2005 - Close all alerts rasied before
' (date) Original code from the web page below,
' http://blogs.technet.com/jonathanalmquist/archive/2008/04/02/mom-2005-close-all-alerts-raised-before-date.aspx
' The modification I made is to get the UTC from the date and time one day ago,
' and close all open alerts whose TimeLastModified property is older than that
' time and date. Change Now-1 to Now-2 for two days ago etc.
'==========================================================================
Set dUTC = CreateObject("WbemScripting.SWbemDateTime")
dUTC.SetVarDate Now-1, True
dtUTC = Left(dUTC,14)
Set objWMI = GetObject("winmgmts://./root/MOM")
strQuery = "select * from MSFT_Alert where ResolutionState <> 255"
Set colAlerts = objWMI.ExecQuery(strQuery)
For Each objAlert In colAlerts
If Len(Trim(objAlert.AlertHistoryComment)) = 0 Then objAlert.AlertHistoryComment = Null
If Len(Trim(objAlert.CustomField1)) = 0 Then objAlert.CustomField1 = Null
If Len(Trim(objAlert.CustomField2)) = 0 Then objAlert.CustomField2 = Null
If Len(Trim(objAlert.CustomField3)) = 0 Then objAlert.CustomField3 = Null
If Len(Trim(objAlert.CustomField4)) = 0 Then objAlert.CustomField4 = Null
If Len(Trim(objAlert.CustomField5)) = 0 Then objAlert.CustomField5 = Null
If Len(Trim(objAlert.Description)) = 0 Then objAlert.Description = Null
If Len(Trim(objAlert.OwnerName)) = 0 Then objAlert.OwnerName = Null
If Len(Trim(objAlert.ResolvedBy)) = 0 Then objAlert.ResolvedBy = Null
If Len(Trim(objAlert.TimeResolved)) = 0 Then objAlert.TimeResolved = Null
If ObjAlert.TimeLastModified <= dtUTC Then
objAlert.ResolutionState = 255
objAlert.Put_
End If
Next