Create MEM Maintenance Windows with offset days and/or weeks.

Create MEM Maintenance Windows with offset days and/or weeks.

Step 1

Open the MEM console on the Site Server and click on the drop down menu in the upper left corner [1] and select ‘Connect via Windows PowerShell ISE’ [2].

No alt text provided for this image

Step 2

This will give you this default script which you need to run [1].

It’ll make sure you have the required PowerShell module installed and have the required MEM drive (your site code).

No alt text provided for this image

After that you should see something like this [2] (LVH is my site code):

No alt text provided for this image

Step 3

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:

No alt text provided for this image


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 [1] and FQDN of your site server [2] 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’.

No alt text provided for this image

Step 4

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 [1] and then the FQDN of your site server [2].

Windows Explorer will now open so you can browse to your ‘CollectionIDs.txt’ (or what ever name you gave your file) [3]. It should only include a list of collection ID’s of the collections you want to check.

No alt text provided for this image

If you don’t have it, you can easily find them in the MEM console.

No alt text provided for this image


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.

No alt text provided for this image

Step 5

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 [3] as you want. Make sure to include all the settings for each section as they are all required.

No alt text provided for this image

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.

No alt text provided for this image
No alt text provided for this image

The output should be similar this:

No alt text provided for this image

Step 6

You can now run the first script again (‘Get MWs v2004.13.ps1’) to verify the settings.

No alt text provided for this image

Script download:

You can download both scripts and the sample input files from my GitHub repository:

https://github.com/larsinus/Public/tree/master/Configuration%20Manager/Maintenance%20Windows

Have fun! ??

Disclaimer:

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.

Jamin A.

IT Strategy & Leadership | Focused on Driving Business Outcomes & Team Success

4 年

Nice work sir

Matt Balzan

MattGPT / Principal Engineer / Consultant / Microsoft EDE

4 年

Awesome Lars! ????

Miguel Angel C.

Senior Consultant in Microsoft Sys, SCCM, Powershell, VMware in DXC TECHNOLOGY. CUATRILINGUAL.

4 年

Nice work!!!. Great. Thanks for sharing it.

要查看或添加评论,请登录

Lars Halvorsen的更多文章

社区洞察

其他会员也浏览了