Quantcast
Channel: Operations Manager - General forum
Viewing all articles
Browse latest Browse all 11941

Computers and watchers to Maintenance Mode

$
0
0

I have a script that puts computers and their respective watchers into maintenance mode by way of the SCOM SDK in 2012.  I look up the watchers via their relationships to the computer through the Health Service.  The script works, except for the critical part:

                If (!$ComputerObject.InMaintenanceMode -or !$HealthServiceWatcher.InMaintenanceMode)
                {
                     Write-Host "Placing $($ComputerObject.Displayname) into Maintenance Mode..." -ForegroundColor Green
                     if(!$HealthServiceWatcher.InMaintenanceMode)
                     {
                        $HealthServiceWatcher.ScheduleMaintenanceMode($StartTime, $EndTime, $Reason, $Comments, "Recursive")
                     }

                     if(!$ComputerObject.InMaintenanceMode)
                     {
                        $ComputerObject.ScheduleMaintenanceMode($StartTime, $EndTime, $Reason, $Comments, "Recursive")
                     }
                }

The first ScheduleMaintenanceMode command works, but he second always fails with

Exception calling "ScheduleMaintenanceMode" with "5" argument(s): "The client has been disconnected from the server. Please call ManagementGroup.Reconnect() to reestablish the connection."

It doesn't matter if I try to set the watcher first or the computer first.  The 2nd command fails.  *However*, if I pause at that point in the script and paste the command into the console - it works!  Then, it still fails trying to run it from the script.

Naturally, I tried $MG.Reconnect() between them, but no luck.

Anyone have a clue on this one? 

Lionel


Viewing all articles
Browse latest Browse all 11941

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>