Skip to content

Instantly share code, notes, and snippets.

@keithga
Last active October 10, 2017 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithga/a4568ce5bdfca8b8b12921e158dc56ba to your computer and use it in GitHub Desktop.
Save keithga/a4568ce5bdfca8b8b12921e158dc56ba to your computer and use it in GitHub Desktop.
TEst switches
Function Test-Switch ( [switch] $Test ) {
# Correct use of a switch Test (True case)
if ( $test ) {
"Do Something"
}
# Bad use of a switch test (False case)
if ( $test -eq $null ) {
"Never going to do it!"
}
# Better use of a switch test (False case)
if ( -not $test ) {
"Don't do it"
}
}
Test-Switch
Test-Switch -Test:$False
Test-Switch -Test
Test-Switch -Test:$True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment