Hey, PowerShell Guy ! How Can I Tell If a Script is Running on the First or Second Monday of a Month?
Scripting games are over, but if you want some more PowerShell execersises , the rest of the scriptcenter including VbScript content might be usefull also.
As you might know, I also like to translate Hey Scripting Guy questions to PowerShell
(For a list of former Hey Scripting Guy translations on this blog and my old one and a list of links my ScriptingGames 2006 PowerShell answers see this post : Scripting Games MMVII PowerShell Competition )
Yesterday I translated another Hey Scripting Guy column answer to PowerShell
How Can I Tell If a Script is Running on the First or Second Monday of a Month?
The PowerShell version I made looks like this
$date = get-date
$Mondays = 1..7 |
Where {
([datetime]$date.tostring("MM/$_/yyyy")).dayOfWeek -eq 'Monday'
} |
Foreach {
$date.tostring("MM/$_/yyyy")
$date.tostring("MM/$($_ +7)/yyyy")
}
if ($Mondays -contains $date.tostring("MM/dd/yyyy")) {
"Carry out the task."
} Else {
"Don't carry out the task."
}
*Tip* Try translating some of the Hey Scripting Guy answers to PowerShell yourself (and better yet post your solutions also)
I think it's good training and lots of fun ;-)
Enjoy,
Greetings /\/\o\/\/