Bird
0
0

What will this PowerShell script output?

medium📝 Command Output Q13 of 15
PowerShell - Scripting Best Practices
What will this PowerShell script output?
try {
  Get-Item 'C:\NonExistentFile.txt'
} catch {
  Write-Output 'File not found'
}
AFile not found
BAn error message about file not found
CNo output
DThe file contents
Step-by-Step Solution
Solution:
  1. Step 1: Understand try-catch behavior

    The script tries to get a file that does not exist, causing an error.
  2. Step 2: Catch block runs on error

    The catch block outputs 'File not found' instead of showing an error.
  3. Final Answer:

    File not found -> Option A
  4. Quick Check:

    Error caught, outputs 'File not found' [OK]
Quick Trick: Try-catch outputs catch message on error [OK]
Common Mistakes:
  • Expecting error message instead of catch output
  • Thinking no output if error occurs
  • Assuming file contents print without file

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes