Bird
0
0

This script on macOS throws an error:

medium📝 Debug Q7 of 15
PowerShell - Cross-Platform PowerShell
This script on macOS throws an error:
Get-Content file.txt | Where-Object { $_ -eq 'test' }

What is the likely cause?
Afile.txt does not exist in current directory
BWhere-Object does not accept script blocks on macOS
CGet-Content is not available on macOS
D$_ is invalid syntax in Where-Object
Step-by-Step Solution
Solution:
  1. Step 1: Check file existence

    If file.txt is missing, Get-Content throws an error.
  2. Step 2: Confirm command support

    Get-Content and Where-Object with $_ script block work on macOS PowerShell.
  3. Final Answer:

    file.txt does not exist in current directory -> Option A
  4. Quick Check:

    Missing file causes Get-Content error [OK]
Quick Trick: Ensure files exist before using Get-Content [OK]
Common Mistakes:
  • Assuming Where-Object unsupported
  • Thinking $_ is invalid
  • Ignoring file presence

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes