Challenge - 5 Problems
PowerShell File Reader 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?
Given a file named
What will be the output of this command?
example.txt containing the lines:HelloWorldWhat will be the output of this command?
Get-Content example.txtPowerShell
Get-Content example.txt
Attempts:
2 left
💡 Hint
Get-Content reads each line as a separate string and outputs them line by line.
✗ Incorrect
Get-Content outputs each line as a separate string, so the output will be two lines: 'Hello' and 'World'.
💻 Command Output
intermediate2:00remaining
What does this command output when reading a file with empty lines?
Assume
What is the output of:
data.txt contains:Line1Line3What is the output of:
Get-Content data.txtPowerShell
Get-Content data.txt
Attempts:
2 left
💡 Hint
Get-Content preserves empty lines as empty strings in the output.
✗ Incorrect
Empty lines in the file are read as empty strings, so the output includes a blank line between Line1 and Line3.
📝 Syntax
advanced2:00remaining
Which command correctly reads the first 3 lines of a file?
You want to read only the first 3 lines of
log.txt. Which command does this correctly?Attempts:
2 left
💡 Hint
Look for the parameter that limits the number of lines read directly.
✗ Incorrect
The -TotalCount parameter tells Get-Content to read only the specified number of lines from the start.
🔧 Debug
advanced2:00remaining
Why does this command fail with an error?
You run:
and get an error. Why?
Get-Content -Pathand get an error. Why?
PowerShell
Get-Content -Path
Attempts:
2 left
💡 Hint
Check if all required parameters have values.
✗ Incorrect
The -Path parameter needs a file path value; omitting it causes an error.
🚀 Application
expert3:00remaining
How to read a file and output only lines containing 'error' (case-insensitive)?
You want to read
server.log and output only lines that contain the word 'error', ignoring case. Which command achieves this?Attempts:
2 left
💡 Hint
Look for the operator that matches text ignoring case.
✗ Incorrect
The '-imatch' operator performs a case-insensitive regex match, filtering lines containing 'error' regardless of case.