Find the groups that belongs a Scom agent

# ——————————————————————————————————————–
# Name: Get-GroupsForOneObject.ps1
# Author: Gustavo Méndez, 23/08/2013
# Version: 1.0
# Description: Displays all groups that one Scom agent belongs
# Change value of variable $stringObject by the server name to find
# ——————————————————————————————————————

# Initialize hashtable array (index will be the group name)


# Declare object to find

$stringObject=”Object Name or Server Name”;

# Find and save the Scom object

$Class = get-monitoringclass -name “Microsoft.SystemCenter.Agent”;

$objectToFind = Get-MonitoringObject -monitoringclass:$Class | ? {$_.displayname -match $stringObject}

# If object is null exit

If (!($objectToFind))
write-host “It doesn’t exist or it could be for example a VMware virtual machine server discovered by Veeam MP without Scom agent”;


# Obtain groups

$mg = (Get-ManagementGroupConnection).ManagementGroup;

$groups = $mg.GetRootPartialMonitoringObjectGroups() | sort DisplayName;

# Find the object in each group

foreach ($group in $groups)

$groupMembers = $group.GetRelatedPartialMonitoringObjects([Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel);

# If group contain members…

if($groupMembers.Count -ne 0)


# Compare each member group with the object to find

foreach ($groupMember in $groupMembers)


if ($groupMember.displayname -match $objectToFind)


# Add group to array

$array.$objectToFind += (“$group, “);





$array.GetEnumerator() | Sort-Object Name | Out-GridView; # Print results in a new window;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: