Bird
0
0

What will be the output of this PowerShell snippet?

medium📝 Command Output Q5 of 15
PowerShell - File and Directory Operations
What will be the output of this PowerShell snippet?
$file = 'C:\Temp\file.txt'
if (Test-Path $file) { 'File exists' } else { 'File missing' }

Assuming C:\Temp\file.txt does NOT exist.
AFile missing
BError: File not found
CFile exists
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check file existence

    The file 'C:\Temp\file.txt' does not exist as per the question.
  2. Step 2: Evaluate the if condition

    Test-Path returns False, so the else block outputs 'File missing'.
  3. Final Answer:

    File missing -> Option A
  4. Quick Check:

    Non-existing path returns False = 'File missing' [OK]
Quick Trick: Test-Path False triggers else block [OK]
Common Mistakes:
  • Assuming output is 'File exists'
  • Expecting error instead of else output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes