Create a Maintenance Window in ConfigMgr with an offset from patch Tuesday

So its that time of year again where it is time to create all those Maintenance Windows for your patch groups. If you are like me and don't want to do them on actual patch Tuesday (not that Microsoft ever had any issues with their patches, right? ) you might miss an option in ConfigMgr to create the MW's with an offset based on patch Tuesday. The reason you might want this is that sometimes the second Wednesday comes before the second Tuesday of the month.

For this reason I have created a PowerShell script to handle the logic and automate the creation of non-recurring MWs.

The script can be found here:

For example, to create a MW on Tuesday one week after patch Tuesday at 18.00 with a duration of 2 hours:

.\New-CMMaintenanceWindow.ps1 -SiteCode  -MaintenanceWindowName "MW Tuesday 1800" -AddMaintenanceWindowNameMonth -CollectionID  -patchTuesday -adddays 7 -StartYear 2018 -StartHour 18 -StartMinute 0 -HourDuration 2 -MinuteDuration 0

To remove last years MW (if they all have a description stating the year) you can fire up a PowerShell prompt with the CM module loaded and run the following snippet.

$collections = @("","")
foreach($collection in $collections){
    Get-CMMaintenanceWindow -CollectionId $collection -MaintenanceWindowName *2017* |foreach {Remove-CMMaintenanceWindow -MaintenanceWindowName $_.Name -CollectionId $collection}

Have fun!


Twitter: @matbg

About the author

Mattias Benninge

5 1 vote
Article Rating
Notify of
Inline Feedbacks
View all comments