Patch Tuesdays 2012

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 {            
param([datetime]$date)            
    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}             
     }            
     $patchTuesday.ToLongDateString()            
}            
            
function Get-PatchTuesday {            
param (            
    [parameter(ValueFromPipeline=$true)]            
    [int]$year = (Get-Date).Year,            
                
    [switch]$nextmonth            
    )            
                 
    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

Leave a Reply