I’m creating a PowerShell donut that shows the state of Health Service Watchers (SCOM) from nested groups in a donut. The query returns 124 objects, each with a unique id (just a counter in the script). The response data also shows 124 objects. However, when I render the data as a donut, it shows 7750 objects. Script is below:
$Group = Get-scomgroup -DisplayName "<Group of nested groups>"
$Members = $Group.GetRelatedMonitoringObjects()
$sgmembers = @()
ForEach($Member in $Members){
$subgroup = $Member.DisplayName
$servergroup = Get-SCOMGroup -DisplayName "$subgroup"
$sgmembers += $servergroup.GetRelatedMonitoringObjects() | Select-Object HealthState, @{N='name';E={$_.DisplayName}}
}
$sgmembers | Add-Member -MemberType NoteProperty "id" -Value 0
$sgmembers | Add-Member -MemberType NoteProperty "state" -Value '0'
$counter = 0
ForEach ($object in $sgmembers){
$counter++
$object.id= $counter
$object.state = if ($object.HealthState = 'Success'){'healthy'}
elseif ($object.HealthState = 'Warning'){'unhealthy'}
elseif ($object.HealthState = 'Error'){'critical'}
elseif ($object.HealthState = 'Uninitialized'){'unknown'}
}
$sgmembers
I’m using id for the value (the only one available to select) and state for the grouping. Any tips? The documentation and examples for this are not awesome, and there is no example i can find on GitHub.