Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-FirstMondayOfMonth
- {
- <#
- comment based help goes here
- #>
- [CmdletBinding ()]
- Param (
- [Parameter(
- Position = 0
- )]
- [ValidateRange (1,12)]
- [int]
- $MonthNumber = (Get-Date).Month
- )
- if ($MonthNumber)
- {
- $Day_1 = Get-Date -Month $MonthNumber -Day 1
- }
- else
- {
- $Day_1 = Get-Date -Day 1
- }
- switch ($Day_1.DayOfWeek.value__)
- {
- 0 {
- $Offset = 1
- break
- }
- 1 {
- $Offset = 0
- break
- }
- default {
- # the "+ 1" is to handle the "off-by-one" array index difference
- $Offset = 7 - $Day_1.Date.DayOfWeek.value__ + 1
- }
- }
- $Day_1.Date.AddDays($Offset)
- }
Add Comment
Please, Sign In to add comment