Calculate What Date Thanksgiving is on with PowerShell

A quick search on the Internet turned up this definition for Thanksgiving: “Thanksgiving Day is a time for many people to give thanks for what they have”.

Based on that definition, I have a long list of things to be thankful for, however, this is a technology related blog site with an emphasis on PowerShell so I’ll focus on being thankful for my PowerShell friends, the PowerShell community, an employer who supports my PowerShell addiction, and a wife & children who put up with me spending countless hours on the computer learning more about PowerShell.

I have many friends throughout the world that I’ve made through the common pursuit of a better understanding and more knowledge of PowerShell. Jason Helmick is one of those friends who recently wrote a blog on Interface Technical Training’s website where he called me a “PowerShell Guru”:


I think it’s awesome to have someone like Jason who is an IT speaker, author (Learn Windows IIS in a Month of Lunches), columnist, PowerShell guru, and IIS guru to write this which was unsolicited. Thank you Jason…

I’m also thankful for an employer who helps support my PowerShell addiction. They’re sending me to the PowerShell Summit North America 2013 next year, they have sent me to Microsoft TechEd North America for the past several years, and have paid for countless PowerShell books. I guess that’s one of the reasons I’ve spent more than the past third of my almost twenty year IT career with the same company.

Now for some Thanksgiving PowerShell fun. I want to know what the date is for Thanksgiving, starting with the current year and for a total of ten years:

((Get-Date).Year..((Get-Date).AddYears(10).Year)) |
ForEach-Object {[datetime]$date = "November 1, $_"
while ($date.DayOfWeek -ne 'Thursday') {$date = $date.AddDays(1)}
Write-Output "In $_, Thanksgiving is on November $($date.AddDays(21).Day)"}