Create MEM Maintenance Windows with offset days and/or weeks.
When everyone is working remotely it’s especially important to have full control of when you update your servers and for some, also the clients. To help with that we can use MEM (aka ConfigMgr) and Maintenance Windows (MW). As many of you know we have the option to create offset days when creating our ADR’s, but we don’t have that option when creating the MW’s. My script with take that into account. Also, it can be a pain to know which collections have MW’s. There is a SSRS report that you may run that will show that, but I like doing it through PowerShell as it’s faster and easier to read. Since there’s no such script built into MEM, I’ve created one for myself which I hope some of you also may enjoy ?.
Open the MEM console on the Site Server and click on the drop-down menu in the upper left corner  and select ‘Connect via Windows PowerShell ISE’ .
This will give you this default script which you need to run .
It’ll make sure you have the required PowerShell module installed and have the required MEM drive (your site code).
After that you should see something like this  (LVH is my site code):
I’ve created two scripts that you can download from my GitHub repository (download links at the end of the article).
You want to download these two scripts:
But I’ve also included some sample files for the input files which are required by the scripts (‘CollectionIDs.txt’ and ‘MWSettings.json’).
Optional 1: Edit the ‘Get MW’s v2004.13.ps1’ script and add your site code  and FQDN of your site server  to the script. It’ll ask you for it, but if you’re lazy like me you don’t want to type it each time, but rather just hit enter (using default values from the script).
Optional 2: Edit the ‘Create MWs v2004.13.ps1’ script and do the same changes as in step ‘Optional 1’.
Run the ‘Get MWs v2004.13.ps1’ first to get an overview of which MW’s you have now.
Either hit enter twice if you have edited the script or type your site code  and then the FQDN of your site server .
Windows Explorer will now open so you can browse to your ‘CollectionIDs.txt’ (or whatever name you gave your file) . It should only include a list of collection ID’s of the collections you want to check.
If you don’t have it, you can easily find them in the MEM console.
If you don’t see the column, right click on any column header, and select the ‘Collection ID’.
The script will give you an output like this where you can see the name, start time, if it’s based on local or GMT time, duration and if it’s enabled or not. Also, if no MW is defined.
When you run the ‘Create MWs v2004.13.ps1’, it’ll ask you for the same type of information. Site code, site server FQDN and a settings file. The input file for this script contains a bit more information and is created as a .json file. Look at my sample file and adjust to fit your needs. Add/remove as many sections  as you want. Make sure to include all the settings for each section as they are all required.
It starts with cleaning up old MW’s before it’ll calculate what month we are in and if ‘Patch Tuesday’ has been yet. If so, it’ll skip the creation for this month.
It’ll then create MWs for the rest of the current calendar year based on the settings specified in the .json file.
The output should be similar this:
You can now run the first script again (‘Get MWs v2004.13.ps1’) to verify the settings.
You can download both scripts and the sample input file from my GitHub repository:
Have fun! ?
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.