Counting alerts created by a monitor
The following code will demonstrate how to count the number of alerts created by the monitor over the last five days. This can be used for reporting. We can change the time interval just by changing the -5
value in the following code. Also, this code will fetch only closed alerts (code 255
). We can change the following code as per the requirement:
$PastDate = (Get-Date).Date.AddDays(-5) $AllAlerts = Get-SCOMAlert $AlertCount = ($AllAlerts -criteria 'ResolutionState = "255" AND IsMonitorAlert = "True"| Where-Object {$_.LastModified -gt $PastDate }).count $AlertCount