/
GroupInfo.PS1
101 lines (50 loc) · 1.61 KB
/
GroupInfo.PS1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
##################################################################
<#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