Recall & Review
beginner
What does the <code>Select-String</code> cmdlet do in PowerShell?It searches through text or files for patterns that match a regular expression (regex) and returns the matching lines.
Click to reveal answer
beginner
How do you use
Select-String to find the word 'apple' in a file named fruits.txt?Use the command: <br>
Select-String -Path fruits.txt -Pattern 'apple'<br>This searches for 'apple' in the file and shows matching lines.Click to reveal answer
beginner
What is a regular expression (regex) in simple terms?
A regex is like a search pattern made of special characters that helps find text that fits a certain shape or rule, like all words starting with 'a'.
Click to reveal answer
intermediate
How can you make
Select-String search case-insensitively?By default,
Select-String is case-insensitive. To make it case-sensitive, add the -CaseSensitive switch set to $true. The -NotMatch switch is used for inverse matching.Click to reveal answer
beginner
What does the output of
Select-String include when it finds a match?It shows the file name, the line number, and the text of the line where the match was found.
Click to reveal answer
Which cmdlet is used to search text using regex in PowerShell?
✗ Incorrect
Select-String is the PowerShell cmdlet designed for searching text with regex patterns.
What does the pattern
^a match in Select-String?✗ Incorrect
The caret ^ means the start of a line, so ^a matches lines that start with 'a'.
How do you search multiple files with
Select-String?✗ Incorrect
You can use wildcards like *.txt in the -Path parameter to search many files at once.
What switch makes
Select-String return lines that do NOT match the pattern?✗ Incorrect
The -NotMatch switch returns lines that do not match the regex pattern.
If you want to find the word 'cat' regardless of case, which command is correct?
✗ Incorrect
By default, Select-String searches case-insensitively, so just -Pattern 'cat' works.
Explain how you would use
Select-String to find all lines containing a phone number pattern in a text file.Think about how phone numbers look and how regex can match digits and separators.
You got /3 concepts.
Describe the output you get from
Select-String when it finds matches and how you can use that output.Imagine you are looking for a word in many files and want to know exactly where it is.
You got /4 concepts.