You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With SCOM Monitoring, sometimes you want to want to put a certain monitor into "Maintenance Mode", however, monitors cannot be placed into maintenance mode. BUT, the underlying object can,
4
+
which in turn puts the monitor into "Maintenance Mode".
5
+
6
+
For example, the monitor "TCP/IP NetBIOS Service Health" is a core Windows Operating System monitor that looks at the "LmHosts" service to see if it's running or not. This monitor targets the
7
+
Windows Operating System class. Let's say we want to silence this monitor, this does not appear as an option in the MM Scheduler, and rightfully so, instead what we can do is put the TARGET of
8
+
the monitor into maintenance mode. So, if we want to put the "TCP/IP NetBIOS Service Health" monitor into "Maintenance", we need to put the whole Windows Operating System object into maintenance
9
+
for the target server.
10
+
11
+
That's what this script does. It takes the input of the monitor display name to silence, and puts the underlying target into maintenance mode for the set duration in minutes.
12
+
13
+
.NOTES
14
+
For best results, run from a management server, or after connecting to a management group in the current PowerShell process (ex. New-SCManagementGroupConnection -ComputerName "MS1.contoso.com" -Credential (Get-Credential))
15
+
16
+
.AUTHOR
17
+
Lorne Sepaugh
18
+
19
+
.VERSION
20
+
v2.0.0 - July 2024
21
+
v1.0.0 - May 2021
22
+
23
+
.PARAMETERMonitorDisplayName
24
+
This is the Display Name of the monitor that we want to place into maintenance mode (Alias: DisplayName)
25
+
26
+
.PARAMETERComment
27
+
Comment on the reason to place the monitor into maintenance mode
28
+
29
+
.PARAMETERDuration
30
+
Provide the number of minutes the monitor should be placed into Maintenance Mode from the start of the script
31
+
32
+
.PARAMETERComputerName
33
+
You can provide either a path to a text file containing a list of servers (ex. .\ServerList.txt), or an inline comma-delimited list of servers (ex. "server01.contoso.com,server02.contoso.com")
34
+
35
+
.PARAMETERStartMaintenance
36
+
(Default) Indicate that we will be starting maintenance, and set a duration for the maintenance to automatacally end after.
37
+
38
+
.PARAMETERStopMaintenance
39
+
If you need to stop an existing maintenance schedule early.
# If an instance of the target class exists for the current server in our list, continue
115
+
If ($currentInstance-eq$null) {
116
+
# negative path – just go to the next iteration in the loop
117
+
Write-Warning"Maintenance Mode did NOT get set for '$($server)', as no class instances were found for it under monitor '$($monitorDisplayName)'."
118
+
continue
119
+
}
120
+
121
+
# If the current isntance is not already in maintenance mode, continue
122
+
If ($mmCheck-ne$null){
123
+
# negative path – just go to the next iteration in the loop
124
+
Write-Warning"Maintenance Mode was ALREADY scheduled for the '$($currentInstance.DisplayName)' object for '$($server)' and ends at '$($mmCheck.ScheduledEndTime)'."
125
+
continue
126
+
}
127
+
128
+
# Try setting maintenance for the current class instance
# If maintenance mode was set, rejoice, but continue either way
137
+
If ($mmCheck) {
138
+
Write-Information"Maintenance Mode was scheduled for the '$($currentInstance.DisplayName)' object for '$($server)'."
139
+
}
140
+
Else {
141
+
Write-Warning"Maintenance Mode did NOT get set for '$($server)', this could be due to it already being in maintenance, not having the target object, or something else."
142
+
}
143
+
}
144
+
145
+
# If setting the maintenance schedule failed, then tell us why
146
+
Catch {
147
+
Write-Error"Maintenance Mode did NOT get set for '$($server)' due to error: $($_)."
148
+
}
149
+
}
150
+
}
151
+
152
+
153
+
If ($StopMaintenance) {
154
+
155
+
Write-Output"Stopping Maintenance Window for the monitor '$monitorDisplayName'`n"
156
+
157
+
ForEach ($serverin$serverList) {
158
+
159
+
# Get the class instance for the current server in the list
0 commit comments