I'm looking at writing a script that only fires off an email when it's either the first or second Saturday of the month..
All other Saturdays of the month can be ignored. The issue I'm having is that each Saturday has a value of 6 when using Get-Date.. So I need some way of ignoring the 3rd & 4th Saturdays of the month.....
So far I using a If statement and a count variable.. but the script still runs when the third Saturday is triggered... As i've reset the counter.... I'm trying to find the best logic to use for this case..
$StartOfMonth = Get-Date -Year $Year -Month $Month -Day $Day $CurrentWeek = Get-Date -UFormat %V -Year $Year -Month $Month -Day $Day [int]$DayInWeek = $StartOfMonth.DayOfWeek Write-Host 'Day Of Week = ' $DayInWeek Write-Host 'Starting Day Of Month = ' $StartOfMonth.Day Write-Host 'Day of Week = ' $StartOfMonth.DayOfWeek Write-Host 'Week = ' $CurrentWeek $Saturday = $DayInWeek If($Saturday -eq 6 -and $Counter -eq 0) { Write-Host 'Day Is First Saturday Of Month' 'Day = ' $FirstSaturday $Counter++ Write-Host $Counter } ElseIf($Saturday -eq 6 -and $Counter -eq 1){ Write-Host 'Second Saturday of the Month' 'Day =' $StartOfMonth.DayOfWeek $Counter ++ }
Any ideas...
Thanks,
Shaun.