Skip to content
adatum
  • Home
  •  About adatum
  •  Learn Azure Bicep
  •  SCOM Web API
Operations Manager

Schedule maintenance mode for group (easy)

  • 08/06/201507/01/2025
  • by Martin Ehrnst

One of the most annoying things whit System Center Operations Manager is the lack of maintenance mode scheduling built in. (You have some options, with Orchestrator, SCCM etc). One thing I personally struggle with, is to maintenance mode every server during Windows Update since we use WSUS for patching and not SCCM. but that’s not the purpose of this post.

In this post, i will guide you through how you can schedule maintenance mode for a (SCOM) group of computers with tools you already have installed – Powershell and Task Scheduler. In our environment we have some Citrix XenApp servers which are scheduled to reboot every night. Since they boot at the exact same time they are easier to maintenance mode than all other servers that boot randomly during updates.

This post will guide you through the following.

  • Create a dynamic group containing the servers (I will use OU in this example, but you are free to use what ever you like)
  • The Powershell script to run against OpsMgr
  • Configuration of the Scheduled task.

Creating the dynamic group

Under Authoring in your console, create a new group. I have called mine “Citrix Servers” stored in a custom management pack. Under dynamic members you will have to create a formula to populate the group members. Her you can choose the solution that fit your needs, but I will be using OU, as our Citrix servers are stored in their own OU.

Dynamic group based on OU
Dynamic group based on OU

( Object is Windows Computer AND ( Organizational Unit Matches wildcard *OU=Citrix* ) AND True )

If you have some servers in the same OU, that you do not want included in this group. You can add them in the “exculded members” pane. Once your group is created, allow for the “System Center Minute” to complete, and if everything is OK, you should see your servers.

TIP: Finding a coumputers OU. Check its Properties under Windows Computers

 

The Powershell script and task

Since were not allowed to start maintenance mode ahead in time, we have to rely on our favorite automation tool called Powershell. In the OpsMgr module there is a Cmdlet, Start-ScomMaintenanceMode, which have a time variable.

Start-MaintenanceMode on technet

param($ManagementServer, $GroupName, $Minutes, $Reason, $Comment)

Import-Module OperationsManager #Import the opsmgr module
New-SCOMManagementGroupConnection -ComputerName $ManagementServer #connect to MS
$SCOMGroup = Get-SCOMGroup | where {$_.DisplayName -like "$GroupName"} #Get the scom group to maintenance
$Time = ((Get-Date)).AddMinutes(($Minutes)) #get time and date. Add minutes. This will be how many minutes object is in maintenance mode
Start-SCOMMaintenanceMode -Instance $SCOMGroup -EndTime $Time -Reason "$Reason" -Comment $Comment
-Command "z:\path\script.ps1 - ManagementServer 'ManagementServerFQDN' -GroupName 'GroupDisplayName' -Minutes 'XX' -Reason 'YourReason' -Comment 'YourCommentHere' ; exit $LASTEXITCODE"

Creating the task

Start by creating a new Scheduled task. Under triggers, set the time and all other configuration you will need.

Under ‘actions’ browse to system32 and add powershell as the program to run. (C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe) Under arguments, edit to fit your needs and paste in the above.

Reasons accepted

— PlannedOther
— UnplannedOther
— PlannedHardwareMaintenance
— UnplannedHardwareMaintenance
— PlannedHardwareInstallation
— UnplannedHardwareInstallation
— PlannedOperatingSystemReconfiguration
— UnplannedOperatingSystemReconfiguration
— PlannedApplicationMaintenance
— ApplicationInstallation
— ApplicationUnresponsive
— ApplicationUnstable
— SecurityIssue
— LossOfNetworkConnectivity

Verify that everything works as expected

Event Viewer

mainteventID

Operations Console

MaintFinish

 

Hope this get you on your way to schedule maintenance mode. When I decide to use SCCM to do our patching, or we come up with another idea, I will let you know.

As always – complete this in your test environment to confirm it’s working.
PS: Operations Manager 2016 will have scheduling built in.

Share this:

  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit
Operations Manager

Export overrides to CSV, XML & HTML

  • 23/03/201507/01/2025
  • by Martin Ehrnst

To accomplish an internal goal, this script has been updated to accept parameters.

New version is available here and can be used like this Export-Overrides -managementserver -path -type -suffix

**

Originally, this script was published by Daniele Muscetta and Pete Zerger over at SystemCenterCentral.com. I adopted Dieter Wijckmans version to fit our needs.

Basicly we all need to find our way to document how our OpsMgr environment is configured. We all have our ways (some not) and we first started out using exporting our MP’s to excel with MPViewer where we manually added colours to rules that where disabled. That worked good for us, and we still use this method when we import management packs the first time, but maintaining these documents can be tough. For some time i have exported all unsealed management packs used for overrides to .csv files, and used those to track changes. Today i was asked if i could make them easier to read. Therefor i took the script we have been using (credits in top post) and modified it to include XML, CSV and HTML exports. With the HTML we are able to easily read the overrides, we can use CSV to edit in excel and XML export (you all know this) can be imported back to OpsMgr in case you need it.

In order to get this script running. You have to set your export path, enable or disable export types and define a suffix for your overrides management pack. All this is done in the “configuration area”

#====================================================================================================================
# AUTHOR:	DieterWijckmans (Dieter -Wijckmans -inovativ - be)
# DATE:		03/08/2012
# Name:		Export-Overrides2012.PS1
# Version:	1.2
#
# MODIFIED BY: MartinEhrnst (m a r t i n - e h r n s t - n o)
# MODIFY DATE: 18/03/2015
#
# COMMENT:	Export all your overrides to a CSV, XML & HTML files to keep for your reference.
#			Based on script of DanieleMuscetta and PeteZerger
#			http://www.systemcentercentral.com/BlogDetails/tabid/143/IndexID/78323/Default.aspx
#           
# 
# Usage:	Change your Management pack suffix, export location and Export types YES/NO.
#           Run script manually or with you favorite automation tool
#DontHassleTheCode
#
#=====================================================================================================================

#############################################################
################# CONFIGURATION AREA ########################
#Set export location
$locationroot = "PATH"
#Define your Overrides suffix
$MPSuffix = "SUFFIX"
#export methods
$CSV = "NO" #CSV export to use in excel etc.
$HTML = "YES" #HTML for easier readability
$XML = "YES" #enable if you want to import back toOpsMgr
################ END CONFIGURATION AREA ######################
##############################################################

#HTML OUTPUT STYLING
$Header = @""@ ##This will read out your server name. Run from a management server. $objCompSys = Get-WmiObject win32_computersystem $inputScomMS = $objCompSys.name #Initializing the Ops Mgr 2012 Powershell provider# Import-Module -Name "OperationsManager" New-SCManagementGroupConnection -ComputerName $inputScomMS #Error handling setup $error.clear() $erroractionpreference = "SilentlyContinue" $thisScript = $myInvocation.MyCommand.Path $scriptRoot = Split-Path(Resolve-Path $thisScript) $errorLogFile = Join-Path $scriptRoot "error.log" if (Test-Path $errorLogFile) {Remove-Item $errorLogFile -Force} #Define the backup location #Get date $Backupdatetemp = Get-Date $Backupdatetemplocal = ($Backupdatetemp).tolocaltime() $Backupdate = $Backupdatetemplocal.ToShortDateString() $strBackupdate = $Backupdate.ToString() #Define backup location if((test-path $locationroot) -eq $false) { mkdir $locationroot } $locationfolder = $strbackupdate -Replace "/","-" $location = $locationroot + $locationfolder + "\" new-item "$location" -type directory -force #Delete backup location older than 15 days #To make sure our disk will not be cluttered with old backups we'll keep 15 days of backup locations. $Retentionperiod = "15" $folders = dir $locationroot echo $folders $now = [System.DateTime]::Now $old = $now.AddDays("-$Retentionperiod") foreach($folder in $folders) { if($folder.CreationTime -lt $old) { Remove-Item $folder.FullName -recurse } } #gets all UNSEALED MAnagement Packs with your defined suffix $mps = get-SCOMmanagementpack | where {$_.Sealed -eq $false -and $_.DisplayName -like "*$MPsuffix"} #loops thru them foreach ($mp in $mps) { $mpname = $mp.name Write-Host "Exporting Overrides info for Management Pack: $mpname" #array to hold all overrides for this MP $MPRows = @() #Gets the actual override objects $overrides = $mp.GetOverrides() #loops thru those overrides in order to extract information from them foreach ($override in $overrides) { #Prepares an object to hold the result $obj = new-object System.Management.Automation.PSObject #clear up variables from previous cycles. $overrideName = $null $overrideProperty = $null $overrideValue = $null $overrideContext = $null $overrideContextInstance = $null $overrideRuleMonitor = $null # give proper values to variables for this cycle. this is what we can then output. $overrideName = $override.Name $overrideProperty = $override.Property $overrideValue = $override.Value trap { $overrideContext = ""; continue } $overrideContext = $override.Context.GetElement().DisplayName trap { $overrideContextInstance = ""; continue } $overrideContextInstance = (Get-SCOMMonitoringObject -Id $override.ContextInstance).DisplayName if ($override.Monitor -ne $null){ $overrideRuleMonitor = $override.Monitor.GetElement().DisplayName } elseif ($override.Discovery -ne $null){ $overrideRuleMonitor = $override.Discovery.GetElement().DisplayName } else { $overrideRuleMonitor = $override.Rule.GetElement().DisplayName } #fills the current object with those properties $obj = $obj | add-member -membertype NoteProperty -name overrideName -value $overrideName -passthru $obj = $obj | add-member -membertype NoteProperty -name overrideProperty -value $overrideProperty -passthru $obj = $obj | add-member -membertype NoteProperty -name overrideValue -value $overrideValue -passthru $obj = $obj | add-member -membertype NoteProperty -name overrideContext -value $overrideContext -passthru $obj = $obj | add-member -membertype NoteProperty -name overrideContextInstance -value $overrideContextInstance -passthru $obj = $obj | add-member -membertype NoteProperty -name overrideRuleMonitor -value $overrideRuleMonitor -passthru #adds this current override to the array $MPRows = $MPRows + $obj } #FILE EXPORT - SEE CONFIGURATION AREA #CSV if ($csv -eq "YES"){ $filename = $location + $mp.name + ".csv" $MPRows | Export-Csv $filename } #XML see configuration if ($XML -eq "YES"){ Export-SCOMManagementPack -ManagementPack $mps -Path $location } #HTML see configuration $filename = $location + $mp.name + ".html" if ($HTML -eq "YES"){ $MPRows | ConvertTo-Html -Title "Overrides For $mp" -Head $Header | Out-File $filename } }

 

Share this:

  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Reddit (Opens in new window) Reddit

Posts pagination

1 … 8 9 10

Popular blog posts

  • SCOM Alerts to Microsoft Teams and Mattermost
  • Windows Admin Center with SquaredUp/SCOM
  • SCOM Task to restart Agent - am i complicating it?
  • Azure Application registrations, Enterprise Apps, and managed identities
  • How to move Azure blobs up the path

Categories

Automation Azure Azure Active Directory Azure Bicep Azure DevOps Azure Functions Azure Lighthouse Azure Logic Apps Azure Monitor Azure Policy Community Conferences CSP Monitoring DevOps GitHub Guest blogs Infrastructure As Code Kubernetes Microsoft CSP MPAuthoring OMS Operations Manager Podcast Powershell Uncategorised Windows Admin Center Windows Server

Follow Martin Ehrnst

  • X
  • LinkedIn

RSS feed RSS - Posts

RSS feed RSS - Comments

Microsoft Azure MVP

Martin Ehrnst Microsoft Azure MVP
Adatum.no use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. Cookie Policy
Theme by Colorlib Powered by WordPress