четверг, 26 июля 2018 г.

scom, get health hierarchy

if (-not (get-module OperationsManager)) {
    Import-Module OperationsManager
}

function GetMonitorTree($item, $level) {
        "{0}{1} ({2})" -f "".PadLeft($level, '-'), $item.item.MonitorDisplayName, $item.item.HealthState | out-host
        foreach($child in ($item.ChildNodes | where {@("Success", "Uninitialized") -notcontains $_.Item.HealthState})) {
            GetMonitorTree -item $child -level ($level+1)
        }
}

$objs = Get-SCOMClass -id 046ce89d-e1e2-e18e-d891-96e004f6ed5f | Get-SCOMMonitoringObject

foreach($obj in $objs) {
    "`n{0}\{1}" -f $obj.Path, $obj.DisplayName | out-host
   
    $hierarchy = $obj.GetMonitoringStateHierarchy()

    GetMonitorTree -item $hierarchy -level 1
}