Menu Close

Fix Maintenance Mode Schedules after a DST time change

 

Quick Download:  https://gallery.technet.microsoft.com/SCOM-Scheduled-Maintenance-3742485f

 

Maintenance Mode Schedules are a new feature since SCOM 2016.  However, one of the challenges with these schedules, is that they run one hour off their intended schedule time, after a Daylight Savings Time change.

For instance, if you look at an existing schedule, you can see that the intended run time for Maintenance Mode is 6pm, however, since the DST event, the next run time is calculated at 7pm:

 

image

 

A simple way to fix this, is to update the schedule effective beginning date to a day AFTER the DST time change.

I created a script which will loop through all your schedules, and update the “Effective Beginning” date to “today” when you run the script.  As long as you run this after the DST change, it will correct your schedules:

 

image

 

image

 

 

***WARNING: 

This automation cannot edit schedules that are currently in a  “Running” status.  You will need to stop those schedules from running, or manually edit them.

The script *excerpt* sample is below.  Please download the full script from TechNet gallery above.

 

# Begin MAIN script section #================================================================================= #Get SCOM Maintenance Schedules $MMschedules = Get-SCOMMaintenanceScheduleList $i=0 FOREACH ($schedule in $MMschedules) { $ScheduleID = $schedule.ScheduleId.Guid $ScheduleObj = Get-SCOMMaintenanceSchedule -ID $ScheduleID $ScheduleName = $ScheduleObj.ScheduleName $ActiveStartTime = $ScheduleObj.ActiveStartTime $ActiveEndDate = $ScheduleObj.ActiveEndDate $ScheduleStatus = $ScheduleObj.Status #Check to see if the Schedule is currently running and skip if it is IF ($ScheduleStatus -ne "Running") { #Check to see if ActiveEndDate is in the past (Expired schedule) and only continue if it is IF ($ActiveEndDate -gt $StartTime) { #Check to see if Active Start time is in the future and skip if it is IF ($ActiveStartTime -lt $StartTime) { $ActiveStartHour = $ActiveStartTime.Hour $ActiveStartMinute = $ActiveStartTime.Minute $NewStartDateTime = Get-Date -Hour $ActiveStartHour -Minute $ActiveStartMinute -Second "00" Write-Host "Modifying ($ScheduleName) with existing start time of ($ActiveStartTime) to NEW start time of ($NewStartDateTime)." Write-Log -Result INFO -Message "Modifying ($ScheduleName) with existing start time of ($ActiveStartTime) to NEW start time of ($NewStartDateTime)." #Edit the schedule. Comment out this line to test the script taking no action Edit-SCOMMaintenanceSchedule -ScheduleId $ScheduleID -ActiveStartTime $NewStartDateTime $i++ } ELSE { Write-Host "Skipping ($ScheduleName) because the schedule start time is in the future. Current schedule start time is: ($ActiveStartTime)." Write-Log -Result INFO -Message "Skipping ($ScheduleName) because the schedule start time is in the future. Current schedule start time is: ($ActiveStartTime)." } } ELSE { Write-Host "Skipping ($ScheduleName) because the schedule end date is already expired. Current schedule end date is: ($ActiveEndDate)." Write-Log -Result INFO -Message "Skipping ($ScheduleName) because the schedule end date is already expired. Current schedule end date is: ($ActiveEndDate)." } } ELSE { Write-Host "WARNING: Skipping ($ScheduleName) because it is currently running. Running schedules cannot be edited." Write-Log -Result WARN -Message "WARNING: Skipping ($ScheduleName) because it is currently running. Running schedules cannot be edited." } } Write-Host "Operation complected. Modified ($i) MM schedules." Write-Log -Result INFO -Message "Operation completed. Modified ($i) MM schedules." #================================================================================= # End MAIN script section

 

Let me know if you have any questions, comments, or recommendations!

 

Quick Download:  https://gallery.technet.microsoft.com/SCOM-Scheduled-Maintenance-3742485f

5 Comments

  1. Pingback:Fix SCOM Maintenance Mode Scheduler schedules after a DST time change | SCOM Maintenance Mode Scheduler

  2. Hubo Bomo

    Thank you very much!! Really helpful 🙂

    Not sure why but it didn’t work for me. I only had one schedule affected and it was skipped.
    I updated the script to compare the “Hour” between $schedule.NextScheduledRunTime and $ScheduleObj.ActiveStartTime
    It was more accurate for me:

    $NextScheduledRunTime = $schedule.NextScheduledRunTime
    if ($NextScheduledRunTime.Hour -ne $ActiveStartTime.Hour)
    {
    Write-Host “Modify ($ScheduleName)`nNextScheduledRunTime ‘$NextScheduledRunTime’`nActiveStartTime ‘$ActiveStartTime'”

  3. Thomas Bott

    Hello Kevin,

    this script is going well.
    I added a new function to create the event log because I was missing it at the beginning.

    #Function for check log File
    Function Check-Logfile {
    Param(
    [Parameter(Mandatory=$True)]
    [string]$FilePath
    )

    If(Test-Path -Path $FilePath){
    Write-Host “Logfile exist on $FilePath” -ForegroundColor Green
    } Else {
    # Create log File
    Write-Host “Logfile $FilePath does not exist. It will be created.” -ForegroundColor Yellow
    $Logfile = (New-Item ($FilePath) -ItemType File -Force).FullName

    # Write Header
    $Line = “{0,-19}{1,-8}{2}” -f “TimeStamp”,”,Typ”,”,Message”
    Add-Content $LogFile -Value $Line
    }
    }

    I perform this function once according to your whoami.


    $whoami = whoami
    # Log File
    Check-Logfile -FilePath $LogFile

  4. Lee M

    Hey Kevin,

    Thanks for the heads up! I’ve recently implemented maintenance mode schedules, so it’s good to know about this before it occurs 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *