Skip to content

Instantly share code, notes, and snippets.

@keithga

keithga/test-switches.ps1

Last active Oct 10, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.