Challenge - 5 Problems
PowerShell String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell command?
Consider the following command:
$result = 'HelloWorld' -like 'Hello*'What is the value of
$result?PowerShell
$result = 'HelloWorld' -like 'Hello*' Write-Output $result
Attempts:
2 left
💡 Hint
The -like operator uses wildcard matching with * as any characters.
✗ Incorrect
The string 'HelloWorld' matches the pattern 'Hello*' because it starts with 'Hello' followed by any characters, so the result is True.
💻 Command Output
intermediate2:00remaining
What does this PowerShell command output?
Given the command:
$result = 'PowerShell123' -match '\d{3}'What is the value of $result?PowerShell
$result = 'PowerShell123' -match '\d{3}' Write-Output $result
Attempts:
2 left
💡 Hint
The -match operator returns True if the regex pattern matches anywhere in the string.
✗ Incorrect
The pattern '\d{3}' looks for three digits in a row. 'PowerShell123' ends with '123', so the match is found and the result is True.
📝 Syntax
advanced2:00remaining
Which option correctly uses -like to check if a string ends with '.txt'?
You want to check if the variable
$fileName ends with '.txt' using the -like operator. Which of these is correct?Attempts:
2 left
💡 Hint
The * wildcard matches any characters before '.txt' at the end.
✗ Incorrect
To check if a string ends with '.txt', the pattern should be '*.txt' where * matches any characters before '.txt'.
💻 Command Output
advanced2:00remaining
What is the output of this PowerShell snippet?
Analyze the code:
$text = 'Data123'
if ($text -match '^Data\d+$') { 'Match' } else { 'No Match' }What will it output?PowerShell
$text = 'Data123' if ($text -match '^Data\d+$') { 'Match' } else { 'No Match' }
Attempts:
2 left
💡 Hint
The regex ^Data\d+$ means string starts with 'Data' followed by one or more digits till end.
✗ Incorrect
The string 'Data123' matches the pattern because it starts with 'Data' and ends with digits only, so output is 'Match'.
🧠 Conceptual
expert2:00remaining
Which statement about -like and -match is TRUE in PowerShell?
Choose the correct statement about the difference between -like and -match operators.
Attempts:
2 left
💡 Hint
Think about pattern types and default case sensitivity.
✗ Incorrect
-like uses simple wildcard patterns (*, ?) and is case-insensitive by default. -match uses full regular expressions and is also case-insensitive by default.