SCCM 2012 – Creating maintenance windows via PowerShell

After years of manually creating maintenance windows for our server patching and being too lazy to create a script for it, I ran across a good article by Jeroen Erkelens on creating maintenance windows via a PowerShell script.  You can read Jeroen’s post here.  Jeroen’s script is great but relies on hard-coded dates in a CSV file.  I wanted something that would set the maintenance windows based on a static number of days after Patch Tuesday.

I then found another great piece of PowerShell code by Wilson Souza on TechNet which gives an example of how to retrieve the date for the second Tuesday of the month.  You can see Wilson’s post here.

I mashed these two scripts together along with some of my own code to create this script.  It takes a CSV file as an input, here’s an example:

Fields:
Collection – The collection ID that you want to set the maintenance window on.
DaysPastPatchTuesday – The number of days past Patch Tuesday for the MW.
MWStart – The start time of the MW.
MWEnd – The end time of the MW.
OtherData – Anything…  I personally use this for the collection name so I know which collection I’m looking at.

 

 

Leave a Reply