Last active
August 28, 2018 03:53
-
-
Save jjbaumgartner/8888cd1a39413e4756e77ef88be493dc to your computer and use it in GitHub Desktop.
Simple function to get the Nth ___day after a given date. Good for finding Patch Tuesday (2nd Tuesday of the month) or for scheduling your patches (pipelining, second Saturday after the second Tuesday of the month)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-NthDay { | |
[CmdletBinding()] | |
Param( | |
$Nth = 2, | |
$Day = 'Tuesday', | |
[Parameter(ValueFromPipeline = $true)]$StartDate = (Get-Date "00:00:00") | |
) | |
# Calculate the next 7*$Nth days worth of dates... | |
# ...grab each one that is the weekday we're looking for... | |
# ...and then grab the Nth-1 (proper arrays start at 0) of those days. Poof, you have the Nth ___day of the month | |
(0..(7 * $Nth) | Foreach-Object { (Get-Date $StartDate).AddDays($_) } | Where-Object { $_.dayofweek -eq $Day })[$Nth - 1] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment