November 2018
Intermediate to advanced
566 pages
17h 15m
English
Let's combine the two scripts from the previous recipe, Using Switch-Case conditions to control script flow.
Open a new file and type in the following:
$Date = Get-Date
if ($Date.DayOfWeek -in 'Saturday', 'Sunday') {
Write-Host 'We party on weekends!' -BackgroundColor Yellow -ForegroundColor Black
}
elseif ($Date.DayOfWeek -eq 'Wednesday') {
Write-Host 'Half the week is over, and I want to do so much more!'
}
else {
Write-Host 'Work is worship. Ahem!'
}
Start-Sleep -Seconds 5 $Date = Get-Date switch ($Date.DayOfWeek) { 'Monday' { Write-Output 'Wear red.'; break } 'Tuesday' { Write-Output 'Wear violet.'; break } 'Wednesday' { Write-Output 'Wear indigo.'; break } 'Thursday' { Write-Output 'Wear blue.'; break } 'Friday' { Write-Output ...Read now
Unlock full access