$alertsCount = 0
$alertsByObjectHash = @{}
$alertsByObject = Get-SCOMAlert -ResolutionState 0 | group MonitoringObjectId
if (!$alertsByObject)
{
# do nothing, alerts count is zero as default
}
else
{
function PopulateClassHash($class)
{
if (!$allMGRelatedClassHash.ContainsKey($class.Id))
{
$allMGRelatedClassHash.Add($class.Id, $class.Name)
# recursively get target classes in relationships with source is current class and add into the hashtable
$relationships = @(Get-SCOMRelationship -Source $class) | Where {$_.Base.GetElement().Name -ne "System.Reference"}
if ($relationships)
{
foreach ($relationship in $relationships)
{
PopulateClassHash $relationship.Target.Type.GetElement()
}
}
}
}
foreach ($member in $mgMembers)
{
$cls = $member.GetClasses()
foreach ($c in $cls)
{
if (!$firstLvlMemberClassHash.ContainsKey($c.Id))
{
$firstLvlMemberClassHash.Add($c.Id, $c.name)
}
}
}
$allMGRelatedClassHash = @{}
# populate the all MG related class hashtable
foreach ($firstLvlMember in $firstLvlMemberClassHash.GetEnumerator())
{
$firstLvlClass = Get-SCOMClass -Id $firstLvlMember.Name
PopulateClassHash $firstLvlClass
}