PowerShell Script to place SCOM 2012 SP1 agent(s) in Maintenance Mode

I had to help a customer to place his Citrix servers in Maintenance Mode during the routine reboot.
He was trying to use the example in the MSDN and it was not working throwing the error bellow
As it turns out you have to get an instance of the <Microsoft.Windows.Computer> class for it to work.

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

Start-SCOMMaintenanceMode : The client has been disconnected from the server. Please call ManagementGroup.Reconnect() to reestablish the connection.

At C:\Scripts\SCOMAGENTMM.ps1:15 char:5

+ Start-SCOMMaintenanceMode -Instance $instance -EndTime $Time -Reason $reason ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidOperation: (Microsoft.Syste...anceModeCommand:StartSCMaintenanceModeCommand) [Start-SCOMMaintenanceMode], ServerDisconnectedE

xception

+ FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.OperationsManagerV10.Commands.StartSCMaintenanceModeCommand

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

<#

#>

So instead of just that:

$Instance = Get-SCOMClassInstance -Name $server

He had to use those lines on his script:

$instanceclass= get-scomclass -Name Microsoft.Windows.Computer
$instance = Get-SCOMClassInstance -Class $instanceclass | Where {$_.DisplayNAme -match $server}

<#

#>

So here it goes the complete PS1 script working on SCOM 2012 SP1 Managemet Server

Paste it on the new PowerShell ISE script window replacing computer names and done!

New-SCOMManagementGroupConnection -computername .

$servers = ('MyServer1.MyDomain.com','MyServer2.MyDomain.com','MyServer3.MyDomain.com')

$time=((Get-Date).AddMinutes(6))

$comment ="Citrix reboot routine"

$reason = "PlannedApplicationMaintenance"

foreach ($server in $servers)

{

$instanceclass= get-scomclass -Name Microsoft.Windows.Computer

$instance = Get-SCOMClassInstance -Class $instanceclass | Where {$_.DisplayNAme -match $server}

Write-Host $instance

Start-SCOMMaintenanceMode -Instance $instance -EndTime $Time -Comment $comment -Reason $reason

}

Comments

  • Anonymous
    August 26, 2015
    I was able to use your script you wrote above and produce the following script that puts a server in maintenGood stuff I was able to change up the data you have here and expand on it. Here is a copy of what I did in powershell:

    http://bit.ly/1NI7zEZ

    Thanx for the initial posting this really got me started on the right track


    thom