There are already plenty of good scripts and tools for setting an object in maintenance mode in SCOM 2012 and 2012 R2. In the most cases they are targeting the "System.Computer" SCOM class. It gets really interesting, when also the Veeam Management Pack for VMWare is used in the same environment. In this case there are also objects of another class (Veeam.Virt.Extensions.VMware.VMGUEST) that need to be set in maintenance mode. Those objects are actually the VMware virtual machines monitored by the Veeam management pack.

Parameters

This script accepts three parameters: ComputerName, Hours and Comment.

ComputerName
This script accepts the FQDN of the computer for the $computername parameter and then uses it to get all VMWare virtual machines of class "Veeam.Virt.Extensions.VMware.VMGUEST" with this name. It also does a simple check for the current state of the respective object and it sets the maintenance mode only if "$object.inmaintenancemode -eq $false".

Hours
The parameter $hours is not mandatory and if not provided the maintenance mode is set to a default of 1 hour.

Comment
The parameter $comment is not mandatory.

 

Usage

.\EnterMaintMode.ps1 -Computer "server1.domain.com" -Hours 3 -Comment "Setting Maintenance on Server1 for 3 hours"

 

Additional Information

The script can be easily modified or optimized to meet more complex requirements.