Bird
0
0

Given a file data.txt with these lines:

medium📝 Command Output Q13 of 15
PowerShell - File and Directory Operations
Given a file data.txt with these lines:
Line1
Line2
Line3
What will the command Get-Content data.txt | Select-Object -Last 1 output?
ALine1
BLine3
CLine2
DLine1`nLine2`nLine3
Step-by-Step Solution
Solution:
  1. Step 1: Understand Get-Content output

    Get-Content reads the file line by line, outputting each line as a separate string.
  2. Step 2: Understand Select-Object -Last 1

    This selects only the last line from the input, which is "Line3".
  3. Final Answer:

    Line3 -> Option B
  4. Quick Check:

    Last line selected = Line3 [OK]
Quick Trick: Select-Object -Last 1 picks last line from Get-Content output [OK]
Common Mistakes:
  • Thinking it outputs all lines concatenated
  • Selecting the first line instead of last
  • Confusing Select-Object with filtering content

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes