Friday 13th Part II
No not the film
| 001 002 003 004 005 006 007 008 009 010 011 012 013
| function get-fri13 { <# .SYNOPSIS Calculates each Friday 13th for a given year .DESCRIPTION .PARAMETER year Specifies the year as an integer .EXAMPLE for current year get-fri13 for single year get-fr13 2010 for multiple years 2010..2020 | foreach {get-fri13 $_} .INPUTS Year as Integer #> param ( [parameter(ValueFromPipeline=$true)] [int]$year = (Get-Date).Year ) 1..12 | foreach { $d = [datetime]"$_/13/$year" if ($d.DayOfWeek -eq "Friday"){ $d.ToLongDateString() } } } |
With the last friday 13th out of the way for this year I thought I’d convert my script into a function while I was seeing what next year brings. Its the first function in my datetime module and I’ve added some comment based help.
One quick point – if you use mandatory=$true in the parameter block it overrides the default value and expects a value to be given
Technorati Tags:
PowerShell,
dates