0
0
PowerShellscripting~10 mins

Select-String for searching in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to search for the word 'error' in the file 'log.txt'.

PowerShell
Select-String -Path 'log.txt' -Pattern [1]
Drag options to blanks, or click blank then click option'
A'debug'
B'warning'
C'info'
D'error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a pattern that does not match the search word.
Forgetting to put the pattern in quotes.
2fill in blank
medium

Complete the code to search for the word 'fail' in all '.log' files in the current folder.

PowerShell
Select-String -Path [1] -Pattern 'fail'
Drag options to blanks, or click blank then click option'
A'*.log'
B'*.txt'
C'logfile'
D'fail.log'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file extension in the path.
Not using quotes around the path pattern.
3fill in blank
hard

Fix the error in the code to search for the word 'success' in 'output.txt'.

PowerShell
Select-String -Path 'output.txt' -Pattern [1]
Drag options to blanks, or click blank then click option'
A'success'
Bsuccess
C"success"
D'Success'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the pattern string.
Using incorrect capitalization if case sensitivity matters.
4fill in blank
hard

Fill both blanks to search for the word 'warning' in all '.txt' files and ignore case.

PowerShell
Select-String -Path [1] -Pattern [2] -CaseSensitive $false
Drag options to blanks, or click blank then click option'
A'*.txt'
B'warning'
C'Warning'
D'*.log'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file extension in the path.
Using a pattern with uppercase when ignoring case.
5fill in blank
hard

Fill all three blanks to search for the word 'error' in 'app.log' and show only the line numbers.

PowerShell
Select-String -Path [1] -Pattern [2] | Select-Object [3]
Drag options to blanks, or click blank then click option'
A'app.log'
B'error'
C-Property LineNumber
D-Property Line
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting the wrong property like Line instead of LineNumber.
Forgetting quotes around file name or pattern.