Archive for September, 2012

OpsMgr 2012: Group Maintenance Mode via PowerShell

September 21, 2012 Leave a comment

You’ll have to forgive me as I’m going to go through a bit of history in order to explain what I mean by “the way it should be” in the title of this post. I’ve provided a sample script to demonstrate one way to implement this methodology in your environment.

The short version is this:

Group maintenance mode scripts should be just like computer maintenance mode, short and simple. Really, maintenance mode should be an operation we complete in the Operations Console, but as with any other company, time and resource constraints require Microsoft to make choices and set priorities.

In the time of Operations Manager 2007 RTM, SP1 and even R2, many people were going to a lot of unnecessary effort to put groups of objects into maintenance mode. The widely accepted methodology was:

1. Retrieve the group

2. Loop through the objects contained in the group

3. Put object into maintenance mode

4. Go to next object and repeat

This was not very efficient and resulted in a script making lots of calls to Operations Manager 2007 via the SDK.

Then, Steve Rachui (of Microsoft and general System Center renown) showed the world that all you needed to do was put the group object itself into maintenance mode and OpsMgr would take care of the contained objects for you! Basically, recursion (maintenance mode for “this object and contained objects” was assumed and handled for you. (in case you’re interested, that post was titled “Place a Group in Maintenance Mode with PowerShell”)

Fast Forward to OpsMgr 2012

Naturally, I quickly decided to duplicate Steve’s methodology in an OpsMgr 2012 version of the script, only to discover that the assumption of recursion was missing. Fortunately, this is not such a big deal if you delve into the SDK and look into the .ScheduleMaintenanceMode function, which allows for the inclusion of a request for recursion….the implementation of the “this object and contained objects”.

Here’s a sample script that implements group maintenance mode in a concise and efficient manner, with named parameters. The script is so short, the header with the instructions may be longer than the script itself!

Sample Script and Usage

Since this is a function, you need to call the function in your script as shown in the sample script below. This also eliminates the need to specify parameters to be passed into the script at the command line, making scheduling as a Windows Scheduled Task easy.

GroupMaintMode -ScomServer “mmsscom01” -GroupDisplayName “SQL Server 2008 Computers” `
-DurationInMin 10 -Reason “ApplicationInstallation” -Comment “Scheduled weekly maintenance”

#——–Begin Sample Script—————-

# Name: OpsMgr 2012 Group Maintenance Mode
# Description: Puts Groups into Maintenance Mode
# Authors: Pete Zerger and Matthew Long
# Parameters:
# -ScomServer: mandatory parameter containing mgmt server name (Netbios or FQDN)
# -GroupDisplayName: mandatory parameter containing display name of the target group
# -DurationInMin: mandatory parameter containing integer of desired duration in minutes
# -Reason: mandatory parameter containing reason. Acceptable values are UnplannedOther,
# PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation,
# UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration,
# UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance,
# ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable,
# SecurityIssue, LossOfNetworkConnectivity
# -Comment: optional parameter with free text description of your choice

Function GroupMaintMode
#($ScomServer, $GroupDisplayName, $DurationInMin, $Reason, $Comment)

Import-Module OperationsManager
New-SCOMManagementGroupConnection -ComputerName $ScomServer

ForEach ($Group in (Get-ScomGroup -DisplayName $GroupDisplayName))
If ($group.InMaintenanceMode -eq $false)
$group.ScheduleMaintenanceMode([datetime]::Now.touniversaltime(), `
([datetime]::Now).addminutes($DurationInMin).touniversaltime(), “$Reason”, “$Comment” , “Recursive”)


#Usage (calling the GroupMaintMode function)
GroupMaintMode -ScomServer “mmsscom01” -GroupDisplayName “SQL Server 2008 Computers” `
-DurationInMin 10 -Reason “ApplicationInstallation” -Comment “Scheduled weekly maintenance”

#——–End Sample Script—————-


Integrating VMM 2012 and OpsMgr 2012

September 21, 2012 2 comments

amazing post from Kevin Holmen regarding Integrating VMM 2012 and OpsMgr 2012 here