Challenge - 5 Problems
Select-String 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 Select-String command?
Given a file named
What will be the output of this command?
log.txt with the following content:Info: Start process Error: File not found Warning: Low memory Error: Access denied
What will be the output of this command?
Select-String -Path log.txt -Pattern 'Error'
PowerShell
Select-String -Path log.txt -Pattern 'Error'Attempts:
2 left
💡 Hint
Select-String finds all lines containing the pattern.
✗ Incorrect
Select-String searches the file and returns all lines that contain the word 'Error'. Here, two lines match.
💻 Command Output
intermediate2:00remaining
What does this Select-String command output?
Consider this command:
If
What lines will be output?
Get-Content data.txt | Select-String -Pattern '^Start'
If
data.txt contains:End of file Start of process Starting point Stop here
What lines will be output?
PowerShell
Get-Content data.txt | Select-String -Pattern '^Start'Attempts:
2 left
💡 Hint
The caret ^ matches the start of a line.
✗ Incorrect
The pattern '^Start' matches lines that begin with 'Start'. Only 'Start of process' matches because 'Starting point' starts with 'Starting', not 'Start' exactly at the start.
🔧 Debug
advanced2:00remaining
Why does this Select-String command fail?
You run this command:
But it returns an error:
What is the cause?
Select-String -Path 'C:\Logs\app.log' -Pattern Error -CaseSensitive
But it returns an error:
Select-String : A parameter cannot be found that matches parameter name 'CaseSensitive'.
What is the cause?
PowerShell
Select-String -Path 'C:\Logs\app.log' -Pattern Error -CaseSensitiveAttempts:
2 left
💡 Hint
Check the official parameters of Select-String.
✗ Incorrect
Select-String does not have a '-CaseSensitive' parameter. To do case-sensitive search, use '-CaseSensitive' switch in PowerShell 7+, or use regex with '(?i)' for ignore case.
🚀 Application
advanced2:00remaining
How to find lines NOT containing a pattern using Select-String?
You want to find all lines in
server.log that do NOT contain the word 'Warning'. Which command achieves this?Attempts:
2 left
💡 Hint
Select-String does not have a '-NotMatch' parameter.
✗ Incorrect
Select-String does not support '-NotMatch'. Instead, filter results with Where-Object to exclude lines matching the pattern.
🧠 Conceptual
expert2:00remaining
What is the count of matches from this Select-String command?
Given a file
What is the output of:
data.txt with 5 lines:apple banana Apple pie APPLE pineapple
What is the output of:
(Select-String -Path data.txt -Pattern 'apple' -AllMatches).Matches.Count
PowerShell
(Select-String -Path data.txt -Pattern 'apple' -AllMatches).Matches.CountAttempts:
2 left
💡 Hint
By default, Select-String is case-insensitive.
✗ Incorrect
By default, Select-String is case-insensitive. The pattern 'apple' matches 'apple' (line1), 'Apple' in 'Apple pie' (line3), 'APPLE' (line4), and 'apple' in 'pineapple' (line5). With -AllMatches, .Matches collects all individual matches across all lines, and .Count gives the total: 4.