Maintenance windows are useful to ensure that important tasks on devices are run at the right moment. Usually you create a Maintenance Window in the SCCM console butyou can manage your SCCM maintenance Windows using PowerShell. This is useful when you have to create many.

Here’s a simple example but you can get creative. This example will create a Maintenance Window that occurs each fourth day of every 3 months effective the time you create it at 3:00 AM.

We are using the New-CMMaintenanceWindow and New-CMSchedule cmdlet.

You have to know that Maintenance windows can be applied to Application and package, Software update, Compliance settings and task sequences. The maximum duration of a window is 24h.


#Load Configuration Manager PowerShell Module
Import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5)+ '\ConfigurationManager.psd1')

#Get SiteCode
$SiteCode = Get-PSDrive -PSProvider CMSITE
Set-location $SiteCode":"

#Input
Clear-Host
$CollectionName= Read-Host "Enter the collection name to apply Maintenance Window"
$MWName= Read-Host "Enter the desired Maintenance Window name "

#Occurs Fourth day of every months effective the time you create it at 3:00 AM
$Schedule = New-CMSchedule -DurationCount 1 -DurationInterval Hours -RecurCount 1 -DayOfMonth 4 -Start ([Datetime]"3:00")

$Collection = Get-CMDeviceCollection -Name $CollectionName
New-CMMaintenanceWindow -CollectionID $Collection.CollectionID -Schedule $Schedule -Name $MWName


#Other Schedule Syntax Example
#Starts on the current date, On the second Monday of the month, Recurs once
#$Schedule = New-CMSchedule -Start (Get-Date) -DayOfWeek Monday -WeekOrder Second -RecurCount 1 -OffsetDay 0

#Occurs daily forever
#Schedule = New-CMSchedule -DurationInterval Days -DurationCount 0 -RecurInterval Days -RecurCount 1

SCCM Maintenance Windows Powershell Validation

Once you’ve run the script and the Maintenance Windows is created, you can check in the SCCM console or use one of our report.

Console

  • In the SCCM Console
  • Go to Assets and Compliance \ Device Collections
  • Right-Click your collection and select Properties
  • Go to the Maintenance Windows tab and verify that your Maintenance Window has been created
SCCM maintenance windows powershell

Report

You can also verify if your SCCM maintenance windows has been configured properly on your collections using 2 of our reports :

We developed 2 reports related to Maintenance Window. The first report lists all SCCM Maintenance Windows per device. The second one list all SCCM Maintenance Windows per collection.

SCCM Maintenance Windows Report

This report list all your collection settings including the Maintenance Collection. Simply sort by the Maintenance Windows column to see which collections have a maintenance windows applied.

Create SCCM Maintenance Windows using Powershell

Manage SCCM Maintenance Window with PowerShell

You can use other PowerShell cmdlet to manage maintenance windows.

Comments (1)

Ed Rusi

11.12.2018 AT 01:32 PM
Hello there, I have gone through and created all the MW, with or without Powershell. I have them in a good place, all I want to edit is the day. Our company picks days based on Accounting cutoffs and not patch Tuesday. Some moths we patch on Thursday around the 20th, some days on Saturday. I know the dates well in advance and would like to script changing the date only. Start time comes back with 6/23/2018 5:00:00 AM all I want to change is 6/23/2018 to 12/19/2018 and so on. Thank you very much, Ed