Recall & Review
beginner
What does the
-Wildcard parameter do in a PowerShell switch statement?It allows the
switch statement to match input strings using wildcard patterns like * and ?, similar to file name matching.Click to reveal answer
beginner
How do you enable regex matching in a PowerShell
switch statement?Use the
-Regex parameter with switch. This makes the statement treat each case as a regular expression pattern.Click to reveal answer
intermediate
What is the difference between
-Wildcard and -Regex in a PowerShell switch?-Wildcard uses simple wildcard patterns like * and ?. -Regex uses full regular expressions, which are more powerful and flexible but more complex.Click to reveal answer
beginner
Write a simple PowerShell
switch statement using -Wildcard to match strings ending with '.txt'.switch -Wildcard ($file) {
'*.txt' { "Text file found: $file" }
default { "Other file: $file" }
}
Click to reveal answer
intermediate
Explain why you might choose
-Regex over -Wildcard in a switch statement.You choose
-Regex when you need complex pattern matching, like matching specific character sets, repetitions, or positions, which wildcards cannot handle.Click to reveal answer
Which parameter enables wildcard pattern matching in a PowerShell switch statement?
✗ Incorrect
The
-Wildcard parameter allows matching using wildcard patterns like * and ?.What does the
-Regex parameter do in a PowerShell switch statement?✗ Incorrect
The
-Regex parameter treats each case as a regular expression pattern for matching.Which of these is a valid wildcard pattern to match any string ending with '.log'?
✗ Incorrect
The pattern
*.log matches any string ending with '.log' using wildcards.In a switch statement with
-Regex, which pattern matches strings starting with 'Error'?✗ Incorrect
The regex pattern
^Error matches strings that start with 'Error'.What happens if no case matches in a PowerShell switch statement?
✗ Incorrect
If no case matches, the
default block runs if it is defined.Describe how to use the
switch statement in PowerShell with wildcard matching. Include an example.Think about matching file extensions or simple patterns.
You got /3 concepts.
Explain the benefits of using
-Regex in a PowerShell switch statement compared to -Wildcard.Consider pattern complexity and flexibility.
You got /3 concepts.