Challenge - 5 Problems
PowerShell Switch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a simple switch statement
What is the output of this PowerShell script?
PowerShell
switch (3) { 1 { 'One' } 2 { 'Two' } 3 { 'Three' } default { 'Other' } }
Attempts:
2 left
💡 Hint
The switch statement matches the value 3 to the case 3.
✗ Incorrect
The switch statement compares the input value 3 to each case. When it finds 3, it outputs 'Three'.
💻 Command Output
intermediate2:00remaining
Switch with multiple matching cases
What will this PowerShell script output?
PowerShell
switch (4) { {$_ -lt 3} { 'Less than 3' } {$_ -lt 5} { 'Less than 5' } default { '5 or more' } }
Attempts:
2 left
💡 Hint
Switch stops at the first matching case unless -File or -Regex is used.
✗ Incorrect
The value 4 is not less than 3, so the first case is skipped. It is less than 5, so 'Less than 5' is output and switch stops.
📝 Syntax
advanced2:00remaining
Identify the syntax error in switch statement
Which option contains a syntax error in the switch statement?
Attempts:
2 left
💡 Hint
Check the use of colons vs braces in switch cases.
✗ Incorrect
PowerShell switch cases use braces {} for code blocks, not colons. Using colons causes a syntax error.
🚀 Application
advanced2:00remaining
Using switch to process multiple inputs
What is the output of this script?
PowerShell
switch (1, 2, 3) { 1 { 'One' } 2 { 'Two' } 3 { 'Three' } default { 'Other' } }
Attempts:
2 left
💡 Hint
Switch processes each input value separately.
✗ Incorrect
The switch statement processes each value in the array (1,2,3) and outputs matching strings for each.
🧠 Conceptual
expert2:00remaining
Behavior of switch with -Wildcard parameter
Given this script, what is the output?
PowerShell
switch -Wildcard ("apple.txt", "banana.doc", "cherry.txt") { '*.txt' { "Text file: $_" } '*.doc' { "Doc file: $_" } default { "Other file: $_" } }
Attempts:
2 left
💡 Hint
The -Wildcard parameter enables wildcard matching on input values.
✗ Incorrect
With -Wildcard, switch matches each input against wildcard patterns. apple.txt and cherry.txt match '*.txt', banana.doc matches '*.doc'.