Microsoft System Center Operations Manager

OpsMgr Agent Maintenance Mode By Registry Management Pack 

Version: 1.0.1.13

              Developed by:  Jason Daggett

                                           Microsoft

                                           Sr. Premier Field Engineer

 

Management Pack Description

 

This management pack was designed to assist users without SCOM privileges the ability to put systems into maintenance mode. OpsMgr Agent Maintenance Mode By Registry Management Pack distributes a PowerShell file called StartSCOMAgentMM.ps1. This file writes registry entries with Reason, Comment, Duration and the computer name. It also sets a trigger that a rule looks for to start the collection process from the registry and send the data to the SCOM Management Server. This rule that runs every 5 minutes by default to detect if an agent has been told by a user to be put into Maintenance Mode.

 

Management Pack Requirements

 

Products

 

System Center Operations Manager

System Center Configuration Manager 2012, 2012 R2, 2016 & Current Branch

PowerShell 2.0+

 

Referenced Management Packs

Microsoft.SystemCenter.Library

Microsoft.Windows.Library

System.Health.Library

System.Library

 

Management Pack Contents

 

Files Included in the Management Pack

 

** Both files are provided for convenience. Only choose to import the sealed (.mp) or unsealed (.xml) Management Pack.

             

OpsMgrAgentMMByRegistry.mpb

o   Rules are Enabled by default

§  See “Rules” section for information about rules, their use, and when to disable them

 

             

Rules

 

SCOM Agent Initiated Maintenance Mode Rule for Registry Key

OpsMgrAgentMMByRegistry.AgentInitiated.Rule

 

Copy StartSCOMAgentMM.ps1 to Microsoft Monitoring Agent Folder

OpsMgrAgentMMByRegistry.OpsMgrAgentMMByRegistry.StartSCOMAgentMM.CopyFile.Rule

 

Registry Keys Written

Registry Keys

 

"hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "StartMMAction"     "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "Duration"

"hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "Reason"

"hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "Comment"

 

PowerShell Script

 

StartSCOMAgentMM.ps1

 

Location: C:\Program Files\Microsoft Monitoring Agent\Agent\StartSCOMAgentMM.ps1

 

## How to use this script

##

## This script requires the OpsMgr Agent Maintnenace Mode By Registry Management Pack in order to pass the information to the SCOM Servers.

##

## Required information -Reason, -Duration, -Comment, & -StartMMAction

##

## Duration is in Minutes and must be greater than 5 minutes.

##

## Reason needs to match up with SCOM Reasons. Please use one of the following:

##     PlannedOther

##     UnplannedOther

##     PlannedHardwareMaintenance

##     UnplannedHardwareMaintenance

##     PlannedHardwareInstallation

##     UnplannedHardwareInstallation

##     PlannedOperatingSystemReconfiguration

##     UnplannedOperatingSystemReconfiguration

##     PlannedApplicationMaintenance

##     UnplannedApplicationMaintenance

##     ApplicationInstallation

##     ApplicationUnresponsive

##     ApplicationUnstable

##     SecurityIssue

##     LossOfNetworkConnectivity

##

## Comments are anything you would like to include, limited to 255 characters and must contain a value

##

## StartMMAction - Yes to start MM

##

## Use Example:

##

## StartSCOMAgentMM.ps1 -Reason 'PlannedOther' -Duration '15' -Comment 'Putting this system into MM for 15 minutes' -StartMMAction 'Yes'

##

 

 

Param([String]$Reason,

      [String]$Duration,

      [String]$Comment,

      [String]$StartMMAction

       )

 

    #region Define Global Functions

    Function isValidReason{

        Param($Reason)

 

        if($Reason -eq "PlannedOther" -or $Reason -eq "UnplannedOther" -or $Reason -eq "PlannedHardwareMaintenance" -or $Reason -eq "UnplannedHardwareMaintenance" -or $Reason -eq "PlannedHardwareInstallation" -or $Reason -eq "UnplannedHardwareInstallation" -or $Reason -eq "PlannedOperatingSystemReconfiguration" -or $Reason -eq "UnplannedOperatingSystemReconfiguration" -or $Reason -eq "PlannedApplicationMaintenance" -or $Reason -eq "UnplannedApplicationMaintenance" -or $Reason -eq "ApplicationInstallation" -or $Reason -eq "ApplicationUnresponsive" -or $Reason -eq "ApplicationUnstable" -or $Reason -eq "SecurityIssue" -or $Reason -eq "LossOfNetworkConnectivity")

        {return $True;}

        Else

        {return $False;}

        }

 

    #region End Define Global Functions

 

    #region Main Script Block

 

    # If Registry Keys are Null, write to event log.        

    if( [string]::IsNullOrEmpty($Duration) -And [string]::IsNullOrEmpty($Reason) -And [string]::IsNullOrEmpty($Comment) -And [string]::IsNullOrEmpty($StartMMAction) ){

       #Log a warning in SCOM

       Write-Host **Reason, Duration, Comment, StartMMAction Parameters are required**

 

       Exit

       }

       else

       {

        $isValidReasonVar = isValidReason $Reason;

        if( $isValidReasonVar -eq $True -and $StartMMAction -eq 'Yes'){

 

            Set-ItemProperty -Path "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "StartMMAction" -Value 1;

            Set-ItemProperty -Path "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "Duration" -Value $Duration;

            Set-ItemProperty -Path "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "Reason" -Value $Reason;

            Set-ItemProperty -Path "hklm:\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\MaintenanceMode" -Name "Comment" -Value $Comment;

 

            Write-Host Maintenance Mode parameters were passed to the registry to be processed by the SCOM Agent. Maintenance Mode will begin shortly.

 

            }

            else

            {

 

            Write-Host The script did not detect a valid SCOM Reason. No Maintenance Mode will be set. Cancelling Script.

 

            }

        }