{"id":1269,"date":"2013-05-22T16:55:51","date_gmt":"2013-05-22T20:55:51","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1269"},"modified":"2013-05-22T16:55:51","modified_gmt":"2013-05-22T20:55:51","slug":"when-are-windows-patches-happening","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/when-are-windows-patches-happening\/","title":{"rendered":"When are Windows patches happening?"},"content":{"rendered":"<p>As most people know, Microsoft releases patches on the second Tuesday of the month.  In some organizations these patches are deployed to development, test and QA systems within a couple of days of the release.  However, production systems can&#8217;t be patched until the next maintenance window.  Assuming this patch window is on a Saturday, we need to find the first Saturday after the second Tuesday.  When looking at a calendar this is pretty simple for most people to figure out.  However, when you need a whole years worth it takes a few minutes to calculate.  What we need is some code to look these up for us&#8230;like this function:<\/p>\n<pre><code class=\"language-1\">\r\nFunction Get-WsusSaturday {\r\n param([datetime]$date=(Get-Date) ) \r\n $numberOfTuesdays=0 \r\n \r\n  1..([datetime]::DaysInMonth( $date.year , $date.month )) | %{ \r\n   $thisDate = Get-Date \"$($date.month)\/$($_)\/$($date.year)\"\r\n   if ([string]$thisDate.DayOfWeek -eq 'Tuesday') {\r\n    $numberOfTuesdays++ \r\n    if ($numberOfTuesdays -eq 2) {  \r\n     $thisDate.AddDays(4).ToLongDateString() \r\n    }\r\n   }\r\n }\r\n}\r\n<\/code><\/pre>\n<p>Line 2: accept the date as a parameter and cast it to a date\/time value, defaulting to today&#8217;s date if nothing is provided<br \/>\nLine 3: max sure we don&#8217;t think its Tuesday already<br \/>\nLine 5: starting on the first of each month, loop through the max number of days in the month<br \/>\nLine 8: if the date is Tuesday, add one to the counter<br \/>\nLine 9: once we find the second Tuesday<br \/>\nLine 10: add 4 more days to find the following Saturday and return the date text<\/p>\n<p>You can take this function and do something creative, like find the next 5 years worth of patch Saturdays.<\/p>\n<pre><code class=\"language-powershell\">\r\n13..18 | %{\r\n  $year = $_\r\n  1..12 | %{ Get-WsusSaturday \"$_\/1\/$year\" }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As most people know, Microsoft releases patches on the second Tuesday of the month. In some organizations these patches are deployed to development, test and QA systems within a couple of days of the release. However, production systems can&#8217;t be &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/when-are-windows-patches-happening\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1269","post","type-post","status-publish","format-standard","hentry","category-scripting"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1269"}],"version-history":[{"count":4,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1269\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1269\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}