PowerShell Function: Get-WeekDayInMonth

Often, IT admins need to workout the first/second/third/fourth Mon/Tue/Wed/Thur/Fri/Sat/Sun of any given month. some good examples are: Prepare themselves for Microsoft’s patching Tuesday of each month Planning for any admin tasks caused by Day Light Saving time change So I wrote this simple function today to calculate the date for any given month & year. Here’s the function: [sourcecode language=”PowerShell”] Function Get-WeekDayInMonth ([int]$Month, [int]$year, [int]$WeekNumber, [int]$WeekDay) { $FirstDayOfMonth = Get-Date -Year $year -Month $Month -Day 1 -Hour 0 -Minute 0 -Second 0 #First week day of the month (i.e. first monday of the month) [int]$FirstDayofMonthDay = $FirstDayOfMonth.DayOfWeek $Difference = $WeekDay

Continue reading
%d bloggers like this: