PowerShell script to automatically close old alerts in SCOM

Published Feb 16 2019 04:31 AM 2,582 Views
First published on TECHNET on Dec 14, 2017
The below PowerShell script can be used to automatically close old SCOM 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) then the script will close the alert for you. This script can help clean up some environments with lot of old alerts which are still active.

Script:

$alertsTobeClosedBefore = 5

$currentDate = Get-Date

Get-SCOMAlert | Where-Object {(($_.ResolutionState -ne 255) -and (($currentDate - $_.TimeRaised).TotalDays -ge $alertsTobeClosedBefore))} |Resolve-SCOMAlert
%3CLINGO-SUB%20id%3D%22lingo-sub-351873%22%20slang%3D%22en-US%22%3EPowerShell%20script%20to%20automatically%20close%20old%20alerts%20in%20SCOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-351873%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20TECHNET%20on%20Dec%2014%2C%202017%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20The%20below%20PowerShell%20script%20can%20be%20used%20to%20automatically%20close%20old%20SCOM%20alerts.%20This%20script%20looks%20for%20active%20alerts%20along%20with%20the%20time%20when%20alert%20was%20created%20(alert%20age).%20If%20the%20alert%20age%20is%20greater%20than%20the%20specified%20number%20of%20days%20(%24alertsTobeClosedBefore)%20then%20the%20script%20will%20close%20the%20alert%20for%20you.%26nbsp%3BThis%20script%20can%20help%20clean%20up%20some%20environments%20with%20lot%20of%20old%20alerts%20which%20are%20still%20active.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3EScript%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20%24alertsTobeClosedBefore%26nbsp%3B%3D%26nbsp%3B5%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20%24currentDate%26nbsp%3B%3D%26nbsp%3BGet-Date%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Get-SCOMAlert%26nbsp%3B%7C%26nbsp%3BWhere-Object%26nbsp%3B%7B((%24_.ResolutionState%26nbsp%3B-ne%26nbsp%3B255)%26nbsp%3B-and%26nbsp%3B((%24currentDate%26nbsp%3B-%26nbsp%3B%24_.TimeRaised).TotalDays%26nbsp%3B-ge%26nbsp%3B%24alertsTobeClosedBefore))%7D%26nbsp%3B%7CResolve-SCOMAlert%3C%2FEM%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-351873%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TECHNET%20on%20Dec%2014%2C%202017%20The%20below%20PowerShell%20script%20can%20be%20used%20to%20automatically%20close%20old%20SCOM%20alerts.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-351873%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%20Operations%20Manager%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 11 2019 10:37 AM
Updated by: