Solution 1:

 

You can run the PowerShell Script which is located here:

https://github.com/souravmahato7/Codes/blob/SCOM/GroupInfo.PS1

 

##################################################################

<#Purpose: This script will help you to identify in how many groups the server is part of #>

# You need to copy this GroupInfo.PS1 file to a location on your Management Server.

# How to Run: GroupInfo.PS1 -computername ServerNameWithFQDN

##################################################################

[CmdletBinding()]


param (

[parameter(mandatory=$true,position=1)]

[string[]]$computername

)

Import-Module Operationsmanager

$array=@{};

# Declare object to find

$stringObject=”$computername”

# Find and save the Scom object

$Class = Get-SCOMClass -name “Microsoft.SystemCenter.Agent”

$objectToFind = Get-SCOMClassInstance -Class $class | ? {$_.Name -like $stringObject}

# If object is null exit

If (!($objectToFind))

{

Write-Host “The Server doesn't have any SCOM agent installed” -ForegroundColor Yellow
exit;
}
# Obtain groups
$groups = (Get-SCOMGroup).DisplayName
# Find the object in each group
foreach ($group in $groups)
{
$Groupinfo = Get-SCOMGroup -DisplayName "$group" -ErrorAction SilentlyContinue
if ($Groupinfo -ne $Null)
{
#Write-Host "Group $group"
$groupMembers = $Groupinfo.GetMonitoringRelationshipObjects()
# If group contain members…
if($groupMembers.Count -ne 0)
{
# Compare each member group with the object to find
foreach ($groupMember in $groupMembers)
{
#Write-Host "Group $group"
if ($groupMember.TargetMonitoringObject -match $objectToFind)
{
# Add group to array
$array.$objectToFind += (“$group, “);
}
}
}
}
}
$array.GetEnumerator() | Sort-Object Name | Out-GridView

 

Solution 2:

 

You need to run a SQL query against OperationsManager database and need to provide the servername. You can find the SQL script here.

 

https://github.com/souravmahato7/SQL/blob/SCOM/SCOMGroupInfoforServer.sql

 

Use OperationsManager
SELECT SourceObjectDisplayName FROM RelationshipGenericView
WHERE TargetObjectDisplayName like '%server.domain.root%'
AND SourceObjectDisplayName IN
(SELECT ManagedEntityGenericView.DisplayName
FROM ManagedEntityGenericView INNER JOIN
(SELECT BaseManagedEntityId
FROM BaseManagedEntity WITH (NOLOCK)
WHERE (BaseManagedEntityId = TopLevelHostEntityId) AND (BaseManagedEntityId NOT IN
(SELECT R.TargetEntityId
FROM Relationship AS R WITH (NOLOCK) INNER JOIN
dbo.fn_ContainmentRelationshipTypes() AS CRT ON R.RelationshipTypeId = CRT.RelationshipTypeId
WHERE (R.IsDeleted = 0)))) AS GetTopLevelEntities ON
GetTopLevelEntities.BaseManagedEntityId = ManagedEntityGenericView.Id INNER JOIN
(SELECT DISTINCT BaseManagedEntityId
FROM TypedManagedEntity WITH (NOLOCK)
WHERE (ManagedTypeId IN
(SELECT DerivedManagedTypeId
FROM dbo.fn_DerivedManagedTypes(dbo.fn_ManagedTypeId_Group()) AS fn_DerivedManagedTypes_1))) AS GetOnlyGroups ON
GetOnlyGroups.BaseManagedEntityId = ManagedEntityGenericView.Id)
ORDER BY SourceObjectDisplayName

Leave a Reply

Your email address will not be published. Required fields are marked *