I’m currently working a neat project with a nice automated deployment process – The Deployment (Powershell) does everything from configuring IIS to Updating SQL with Delta schema changes etc. One of the problems for the people in charge of Ops Manager (or those on-call for that matter) is that they will be spammed with Alert emails if the appropriate servers are not dropped into Maintenance mode when this deployment is run.
The team deploying the latest build don’t want mucking around with SCOM while trying to focus on a Prod release for exmple – What we do… Set appropriate servers to maintenance mode at the start of a deployment and pull them out once its complete. Here’s how we do it:
- Establish a new SCOM Group which our Maintenance Mode script will target when run.:
Each server name in our environment is prefixed with its environment type e.g. PRODWEB1, TESTAPP2, PRODSQL1, etc. I’ve setup a Dynamic group with the following rule to target “PROD” machines (and another for test): ( Object is Windows Computer AND ( NetBIOS Computer Name Contains PROD ) AND True ) - Enable PowerShell remoting on SCOM server so we can utilize the OpsManager Powershell Cmdlets:
Enable-PSRemoting -force
- Add the appropriate Powershell snippits (or add them as functions) to your deployment to enter and Exit Maintenance Mode:
To Enter Maintenance Mode:
enter-pssession -computername scomserver.resdevops.com invoke-command -computername scom1.resdevops.com -scriptblock { Import-Module OperationsManager $Instance = Get-SCOMGroup -displayname "PRODSERVERROUPNAME" | Get-SCOMClassInstance $Time = ((Get-Date).AddMinutes(30)) Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Reason "PlannedOther" -Comment "Code Deployment" } Exit-Pssession
Exit Maintenance Mode:
enter-pssession -computername scomserver.resdevops.com invoke-command -computername scom1.resdevops.com -scriptblock { import-module operationsmanager $Instance = Get-SCOMGroup -displayname "PRODSERVERGROUPNAME" | Get-SCOMClassInstance $MMEntry = Get-SCOMMaintenanceMode -Instance $Instance $NewEndTime = (Get-Date) Set-SCOMMaintenanceMode -MaintenanceModeEntry $MMEntry -EndTime $NewEndTime -Comment "Deployment Complete - Maintenance mode disabled" } Exit-Pssession
Let me know if you have any Questions.
-Patrick