PowerShell for Windows Admins

Nov 13 2011   1:12PM GMT

Patch Tuesdays 2012

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


I’ve shown these functions before but as we head rapidly towards 2012 we need to plan next years schedules.  One perennial for Windows administrators is patching – therefore we need to know patch Tuesdays. This is next years offenders

10 January 2012
14 February 2012
13 March 2012
10 April 2012
08 May 2012
12 June 2012
10 July 2012
14 August 2012
11 September 2012
09 October 2012
13 November 2012
11 December 2012

How do we arrive at these dates – simple look at a Calendar or better still use these functions

function get-secondTuesday {            
    switch ($date.DayOfWeek){            
        "Sunday"    {$patchTuesday = $date.AddDays(9); break}             
        "Monday"    {$patchTuesday = $date.AddDays(8); break}             
        "Tuesday"   {$patchTuesday = $date.AddDays(7); break}             
        "Wednesday" {$patchTuesday = $date.AddDays(13); break}             
        "Thursday"  {$patchTuesday = $date.AddDays(12); break}             
        "Friday"    {$patchTuesday = $date.AddDays(11); break}             
        "Saturday"  {$patchTuesday = $date.AddDays(10); break}             
function Get-PatchTuesday {            
param (            
    [int]$year = (Get-Date).Year,            
    if ($nextmonth){            
        $now = Get-Date            
        $d = Get-Date -Day 1 -Month $($now.Month + 1) -Year $now.Year            
        get-secondTuesday $d            
    else {            
        1..12 | foreach {            
            $d = [datetime]"$_/1/$year"            
            get-secondTuesday $d            

We run the function like this

Get-PatchTuesday -year 2012

It takes the year and for each month in the year creates a datetime object for the first of the month.  That date is fed to the get-secondtuesday function which looks at the day of the week and calculates the second Tuesday.

If your patching Window is a specific day in the month then modify the functions to calculate those dates and feed them straight to your change control process

1  Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • keithsimmons
    A little tweak to make this work if current month is december

     if ($nextmonth){            
            $now = Get-Date            ##modded to work with december roll over
            if ($now.Month -eq 12){
                $d = Get-Date -Day 1 -Month $($now.addmonths(1)).month -Year $($now.addyears(1)).year
                get-secondTuesday $d
            else {       
                $d = Get-Date -Day 1 -Month $($now.Month + 1) -Year $now.Year            
                get-secondTuesday $d            
    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: