Set Maintenance Schedule in OpsMgr with PowerShell

Since System Center 2016 you can set a Schedule in Operations Manager for Maintenance Mode.

Before you could build a Runbook with Orchestrator and use the „Start Maintenance Mode Activity“ there.

But now you can use a PowerShell Script to set the Maintenance Schedule in Operations Manager directly:

Import-Module operationsmanager
$SCOMMgmtServer = 'opsmgr.vaserv.eu'
$DNSName = 'orchestrator.vaserv.eu'
$StartDate= [datetime]::ParseExact('31.05.2018 23:00:00',’dd.MM.yyyy HH:mm:ss‘,$null)
$EndDate = [datetime]::ParseExact('31.05.2018 23:15:00',’dd.MM.yyyy HH:mm:ss‘,$null)
$Duration = NEW-TIMESPAN –Start $StartDate –End $EndDate | Select -ExpandProperty Minutes New-SCOMManagementGroupConnection -ComputerName $SCOMMgmtServer

$FullName = "Microsoft.Windows.Computer:$DNSName"

$MonitorID = ((Get-SCOMMonitoringObject | Where {$_.Fullname -eq $FullName} ).Id).Guid

$Schedule = New-SCOMMaintenanceSchedule -MonitoringObjects $MonitorIId -Duration $Duration -FreqType 1 -ActiveStartTime $StartDate ´
-ActiveEndDate $EndDate -ReasonCode PlannedOther -Comments "Test" -Name "Test Schedule"

Enable-SCOMMaintenanceSchedule $Schedule

 

Starten Sie jetzt Ihren Weg zu Azure!

Los geht's

top