Collections:
Other Resources:
If-Else Conditions in Windows PowerShell Scripts
How to use if-else conditions in Windows PowerShell scripts?
✍: FYIcenter.com
PowerShell script supports the following if-else code block
to help you to perform tasks depending on logical conditions:
If (conditin1) {
task1
} Elseif (condition2) {
task2
...
} Else {
other-task
}
Here is a sample script on how to use if-else conditions:
$h = (Get-Date).Hour
If ($h -ge 6 -and $h -lt 12) {
"Good morning!"
} Elseif ($h -ge 12 -and $h -lt 18) {
"Good afternoon!"
} Elseif ($h -ge 18 -and $h -lt 22) {
"Good evening!"
} Else {
"Why are you not sleeping!?"
}
⇒ Out-Host - Standard Output in Windows PowerShell Scripts
⇐ Logical Operations in Windows PowerShell Scripts
2016-10-30, ∼2896🔥, 0💬
Popular Posts:
What is the "Smart Card Device Enumeration Service (ScDeviceEnum)" system service on Windows Server ...
Can I disable Windows service "Broadcom ASF IP monitoring service v6.0.3" to speedup my computer? Wi...
How to start sc.exe command to create, delete and manage Windows services? sc.exe is a command line ...
Why I am getting the "Warning: Unresponsive Script" message box? How to avoid this message box? When...
If you are using a wireless router to connecting to the Internet through a DSL modem, how many IP ad...