Get Monitor State with Powershell


I have a distributed Application. If the application change healthState I have to send an alert with the child-monitor that is unhealthy.

Is their a way to find out wich of the child monitor does not have the state success?

I have tried:

$serviceObjectsRecursive = $DA.GetRelatedMonitoringObjects(‘Recursive’)
foreach ($instance in $serviceObjectsRecursive )
$monitors = Get-SCOMMonitor -Instance $instance -Recurse
foreach ( $monitor in $monitors)
<#Here I have the problem to get the MonitorState#>


Now that was a challenge! I found the answer by chance from this post from Kevin H. (SCOM Dashboards – Using the PowerShell Grid Widget – Kevin Holman's Blog – Section Dashboard of objects filtered by a Monitor Health State)

$serviceObjectsRecursive = $DA.GetRelatedMonitoringObjects(‘Recursive’) | ? HealthState -EQ Error

foreach ($Instance in $serviceObjectsRecursive ) {
    $MonitorCollection = New-Object -TypeName 'System.Collections.Generic.List[Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitor]'
    #Only get unhealthy Unit monitors
    $Instance | Get-SCOMMonitor -Recurse | ? XMLTag -Match Unit | %{ $MonitorCollection.Add($_) }
    if ($MonitorCollection.Count -gt 0) {
        $Instance.GetMonitoringStates($MonitorCollection) | ? HealthState -EQ Error

I like to filter as we go, of course you can skip or update it (if you want the Warnings as well for example). I have also started with the same $DA as yours (Assume you get the ID from the Alert and go from there, but that should be the easy part)

1 Like

Many thanks to the detailed information.

I have tested it and it is exactly what I was looking for.