OpsMgr – Reset Monitor state with powershell

Facebooktwitterredditpinterestlinkedinmail

I had to use monitor instead of rule (missing expression filtering option in some rule type) but without affecting the object state… well, this is my workaround for this request (part of the script is based on Scotts Moss’s script):

  1. Creating the monitor
  2. uncheck the “Automatically resolve the alert when the monitor returns to a health state”
  3. add the below script as a recover task for the previously created monitor

this powershell script get as a parameter the monitor name. every time alert is generated, the state is being reset for that monitor. change the myRMS.domain.local to your RMS server:

param($monitorName)

$checkSnap = Get-PSSnapin | Where-Object {$_.name -eq “Microsoft.EnterpriseManagement.OperationsManager.Client”}
if ($checkSnap.name -ne “Microsoft.EnterpriseManagement.OperationsManager.Client”)
{
add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;
}
new-managementGroupConnection -ConnectionString:”myRMS.domain.local”;
set-location “OperationsManagerMonitoring::”;
$alerts = get-alert | where-object {$_.Severity -eq “Information” -and $_.ResolutionState -eq “0” -and $_.Name -eq “$monitorName”}

ForEach($alert in $alerts) {
$monitor = get-monitor -criteria “Id = ‘$($alert.MonitoringRuleId)'”
$moncls = get-monitoringClass -id $alert.MonitoringClassId
$moncls| get-monitoringObject -criteria “Id = ‘$($alert.MonitoringObjectId)'” | foreach {$_.ResetMonitoringState($monitor)}
}

[Update 3/14]

A friend of mine (Shahar Nusbaum) took my old script (which was SCOM 2007 R2 oriented) and updated it to SCOM 2012 oriented, so.. here it is:

param($monitorName)

Import-Module -Name operationsManager

#$monitorName = “test event”
$alerts = get-scomalert | where-object {$_.ResolutionState -eq “0” -and $_.Name -eq “$monitorName”}

ForEach($alert in $alerts) {
$monitor = get-ScomMonitor -Id $alert.MonitoringRuleId
Get-SCOMClassInstance -id $alert.MonitoringObjectId | foreach {$_.ResetMonitoringState($monitor)}

}

 

Have fun 🙂

 

4 thoughts on “OpsMgr – Reset Monitor state with powershell

Leave a Reply to sharon Cancel reply

Your email address will not be published. Required fields are marked *