A Quick Lesson in Boolean
I often see scripts that are checking for True/False values using an If/Else statement like the one below. While this technically will work for Boolean values, there are situations where this will not work. For example, if you pass the string value of “False” to the statement above it will evaluate as True. This is because the if condition in...
Switch Statement
switch ($value) { 1 {"It is one."} 2 {"It is two."} 3 {"It is three."} 4 {"It is four."} }
If/ElseIf/Else Statement
# If $value equals 1 write True 1, else if it equals 2 write True 2, else write False if($value -eq 1){ Write-Host "True 1" } elseif($value -eq 2){ Write-Host "True 2" } else { Write-Host "False" }
If/Else Statement
# If $value equals 1 write True, else write False if($value -eq 1){ Write-Host "True" } else { Write-Host "False" }