How to place multiple servers in Maintenance Mode in SCOM 2012

Hi All,

I am trying to place multiple servers in Maintenance Mode in SCOM 2012 but i could not find any PoSh script or any other solution to do it.

Could someone help me please?

Regards, Srini

February 11th, 2015 7:15am

Hi,

Please find the script.

need to have access and you can provide list of servers in text file.

 param([int32]$TimeMin, [string]$Reason, [string]$Comment)
                $api = new-object -comObject 'MOM.ScriptAPI'
                Import-Module operationsmanager
                New-SCOMManagementGroupConnection
                $Servers = Get-Content "ServerList.txt"
                $Time = (Get-Date).Addminutes($TimeMin)
                Foreach ($Server in $Servers)
                {
                                #Get Computer instance
                                $ComputerClass = Get-SCOMClass -Name Microsoft.Windows.Computer
                                $ComputerClassInstance = Get-SCOMClassInstance  -Class $ComputerClass | Where {$_.DisplayName -eq $Server}
                               
                                If ($ComputerClassInstance.InMaintenanceMode -eq $true)
                                {
                                #Write-Host $Server " is in maintenance mode"
                                Write-Host $Server" already under Maintenance Mode or not accessible by SCOM, skipped from script execution" -foregroundcolor "red"
                                $api.LogScriptEvent('MaintenanceModeScript.ps1', 201, 1, "$Server already found under MM, skipped from script execution")
                                }
                                Else
                                {
                                #Write-Host $Server " is NOT in maintenance mode, attempting to put in MM......."
                                If ($ComputerClassInstance -ne $Null)
                                {
                                                $HealthServiceWatcherClass = Get-SCOMClass -name:Microsoft.SystemCenter.HealthServiceWatcher
                                                #Get Health Service Watcher Class instance of the server
                                                $HSWClass = Get-SCOMClass -Name Microsoft.SystemCenter.HealthServiceWatcher
                                                $HSWClassIns = Get-SCOMClassInstance  -Class $HSWClass | Where {$_.DisplayName -eq $Server}
                                                #Starting the maintenance mode
                                                Start-SCOMMaintenanceMode -Instance $HSWClassIns -EndTime $Time -Reason $Reason -Comment $Comment
                                                Start-SCOMMaintenanceMode -Instance $ComputerClassInstance -EndTime $Time  -Reason $Reason -Comment $Comment
                                                Write-Host "Health Service Watcher and Agent server "$Server " kept in maintenance mode for $TimeMin minutes"  -foregroundcolor "green"
                                                $api.LogScriptEvent('MaintenanceModeScript.ps1', 200, 0, "$Server kept in maintenance mode for $TimeMin minutes")
                                }
                                Else
                                {
                                                Write-Host $Server" not found in Domain" -foregroundcolor "red"
                                                $api.LogScriptEvent('MaintenanceModeScript.ps1', 202, 1, "$Server not found in domain")
                                }
                                }
                }

Regards

Free Windows Admin Tool Kit Click here and download it now
February 11th, 2015 9:33am

This could be done from SCOM console. from under Monitoring --> windows computer.

Right click , maintenance mode and start Maintenance mode.

February 12th, 2015 12:19am

Hi,

Please refer to the link below:

OpsMgr 2012: Group Maintenance Mode via PowerShell

http://www.systemcentercentral.com/opsmgr-2012-group-maintenance-mode-via-powershell-the-way-it-should-be/

Note: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 1:18am

Hi Sridhar,

It does not work.

I opened a PS session and connected to the management group using

New-SCOMManagementgroupconnection -computername abc.com

and tried to run the script but it failed with errors.

new-object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed
due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At C:\PS Scripts\MM.ps1:2 char:25
+                  $api = new-object -comObject 'MOM.ScriptAPI'
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

New-SCOMManagementGroupConnection : The Data Access service is either not running or not yet initialized. Check the
event log for more information.
At C:\PS Scripts\MM.ps1:4 char:18
+                  New-SCOMManagementGroupConnection
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Syste...nnectionCommand:NewSCManagementGroupConnectionComma
   nd) [New-SCManagementGroupConnection], ServiceNotRunningException
    + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.Core.Commands.NewSCManagementGroupConnectionCommand

Any Suggestion??

Thanks.

February 12th, 2015 6:34am

Hi,

I use this tool from Tim Mcfadden:

SCOM 2012 Maintenance Mode Scheduler

http://www.scom2k7.com/

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 2:42pm

Hi Agarwal,

I need to place hundreds of servers in MM so doing it from console is not the easiest option.

Thanks

February 12th, 2015 5:01pm

Hi,

Thanks for sharing the link. I hope it addresses my requirement.

Will go through it.

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 5:02pm

Thanks Xin.

It addressed my requirements just perfect.

I have added few cluster servers in that group as well so I believe it would also be put in to maintenance mode and don't throw any alerts, right?

February 13th, 2015 11:38am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics