November 2018
Intermediate to advanced
566 pages
17h 15m
English
This situation will require a whole round of If–ElseIf–Else statements. A more efficient way of handling this situation is to use the Switch–Case construct:
$Date = Get-Date
switch ($Date.DayOfWeek) {
'Monday' { Write-Output 'Red' }
'Tuesday' { Write-Output 'Violet' }
'Wednesday' { Write-Output 'Indigo' }
'Thursday' { Write-Output 'Blue' }
'Friday' { Write-Output 'Green' }
Default { Write-Output 'Orange' }
}
$Date = Get-Date
switch -Wildcard ($Date.DayOfWeek) { 'Monday' { Write-Output 'Red' } 'Tuesday' { Write-Output 'Violet' } 'Wednesday' { Write-Output ...Read now
Unlock full access