Patch Tuesday

Patch Tuesday – the second Tuesday in the month – is the day Microsoft (and other vendors) release their patches. If you want to be able to plan ahead for these dates ( like arranging holiday or sick leave ) these two functions will supply the dates to look out for.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
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
        }   
    }
}

 

Get-PatchTuesday takes a year (default is current year) and works out the first of each month as a date. This is passed to get-secondtuesday to calculate the date the patches will be released.

If the –nextmonth parameter is used then the first of next month is calculated and the patch date for that month retrieved from getsecondtuesday.

Dates for the next few months are

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

Time to start planning.

These functions can be adapted to provide dates for any date that follows the pattern of nth weekday.

Technorati Tags: ,,

Advertisements
This entry was posted in Powershell. Bookmark the permalink.

3 Responses to Patch Tuesday

  1. Pingback: When is the next Patch Tuesday? | Jeff Wouters's Blog

  2. Pingback: Mississippi PowerShell User Group Weekly Meeting Last Night – March 26th | Mississippi PowerShell User Group

  3. Trevor says:

    very nice, but fails for the -nextmonth when the current month is December. This will help…
    if ($nextmonth){
    $now = Get-Date
    if ($now.Month -ne 12){
    $d = Get-Date -Day 1 -Month $($now.Month + 1) -Year $now.Year
    } else {
    $d = Get-Date -Day 1 -Month 1 -Year $($now.Year +1)
    }
    get-secondTuesday $d
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s