-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListSCOMObjects.ps1
140 lines (118 loc) · 5.54 KB
/
ListSCOMObjects.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<#
.Synopsis
Retrieves the instances of the given class along with health
.DESCRIPTION
Retrieves the instances of the given class along with health and and agent status. Please be aware that objects can have multiple tiers IF thats the case script splits and dynamicaly creates ObjectsHostxxx.
.EXAMPLE
.\ListSCOMObjects.ps1 -ManagementServer ms1fqdn -Class "IIS Web Site"
This example class has only one child object
ServerName Object AgentHealth ObjectHealth
---------- ------ ----------- ------------
DrcSkypeFe1.litware.com Skype for Business Server External Web Site True Success
LyncW16Fe3.litware.com Skype for Business Server External Web Site True Success
DrcSkypeFe5.litware.com Skype for Business Server External Web Site True Success
DrcSkypeFe4.litware.com Skype for Business Server External Web Site True Success
LyncW16Fe1.litware.com Skype for Business Server External Web Site True Success
.EXAMPLE
.\ListSCOMObjects.ps1 -ManagementServer ms1fqdn -Class "sql database" | Group-Object -Property ServerName | Select-Object -Property Name,Count | Sort-Object -Property Count -desc
Since we return custom objects group-objects can easily be used for inventory reporting purposes.
Name Count
---- -----
tstFGSDB.litware.com 117
MSSQL1.litware.com 96
MSSQLT1.litware.com 93
SPS13SQLTEST.litware.com 75
MSSQL2.litware.com 74
HDHMICRO01.litware.com 62
ovwccncdbstb.litware.com 60
tstTestDB1.litware.com 56
HDHELEKTR1.litware.com 46
SPS2013SQL.litware.com 44
.EXAMPLE
.\ListSCOMObjects.ps1 -ManagementServer ms1fqdn -Class "sql database"
In this example between the database and the server theres the ObjectHost1 which is the sql server instance.
OjectHost1 : MSSQLSERVER
ServerName : hdhTestDB.srvdmz.com
Object : model
AgentHealth : True
ObjectHealth : Success
OjectHost1 : SQLT1
ServerName : MSSQLXX1.litware.com
Object : Prcher_Config_621
AgentHealth : True
ObjectHealth : Success
OjectHost1 : SQL1
ServerName : tstDBLIVE1.litware.com
Object : xxxBBS
AgentHealth : True
ObjectHealth : Success
OjectHost1 : SQL2
ServerName : CASQL1-V.litware.com
Object : yyy_Reporting
AgentHealth : True
ObjectHealth : Success
.EXAMPLE
.\ListSCOMObjects.ps1 -ManagementServer ms1fqdn -Class "sql database" | ft -AutoSize
OjectHost1 ServerName Object AgentHealth ObjectHealth
---------- ---------- ------ ----------- ------------
MSSQLSERVER cccc.litware.com cbslog True Success
MSSQLSERVER tststst.litware.com ETA_KKST_2015 True Success
WINCCT test1.litware.com DB1 True Success
MSSQLSERVER WWWSQL1.srvdmz.com DB2 True Warning
MSSQLSERVER tstFGSDB.litware.com DBXXX True Success
SQLT1 MSSQLXX1.litware.com prjtest True Success
MSSQLSERVER yyyy.litware.com KOTAX True Success
.EXAMPLE
.\ListSCOMObjects.ps1 -ManagementServer ms1fqdn -Class "sql database" | Export-Csv -Path C:\Temp\result.csv
This example lists the objects and then export to a csv file.
.OUTPUTS
PScustomObject
.NOTES
Please be aware that objects can have multiple tiers IF thats the case script splits and dynamicaly creates ObjectsHostxxx.
#>
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact='Medium')]
[Alias()]
[OutputType([PSCustomOBject])]
Param
(
# ManagementServer to connect
[Parameter(Mandatory=$true)]
[ValidateSet("ms1fqdn", "ms2fqdn", "ms1fqdn3")]
[Alias("ms")]
[string]$ManagementServer,
# Class to Report
[string]$Class
)
Process
{
Import-module OperationsManager
if(!$(Get-SCOMManagementGroupConnection)) {
New-SCOMManagementGroupConnection -ComputerName $ManagementServer
}
Get-SCOMClass -DisplayName $Class | Get-SCOMClassInstance | ForEach-Object {
$SplitResult=$_.Path -split ";"
if ($SplitResult.Count -eq 1) {
$Props=@{}
$Props.ServerName=$SplitResult[0]
$Props.Object=$_.DisplayName
$Props.ObjectHealth=$_.HealthState
$Props.AgentHealth=$_.IsAvailable
New-Object -TypeName PSCustomObject -Property $props | Write-Output
} else {
$Props=@{}
$Props.ServerName=$SplitResult[0]
$Props.ObjectHealth=$_.HealthState
$Props.Object=$_.DisplayName
$Props.AgentHealth=$_.IsAvailable
$i=1
Do {
#New-Variable -Name "Props.Property$i" -Value $SplitResult[$i]
$Props.Add("OjectHost$($i)",$SplitResult[$i])
}
while(++$i -le $SplitResult.Count-1)
New-Object -TypeName PSCustomObject -Property $props | Write-Output
}
}
}