Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q4 of 15
PowerShell - Operators
What will be the output of this PowerShell script?
$x = $false
$y = $true
if (-not $x -and $y) { 'Pass' } else { 'Fail' }
AFail
BPass
C$false
DError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate -not $x

    $x is $false, so -not $false is $true.
  2. Step 2: Evaluate the entire condition

    $true -and $y ($true) results in $true.
  3. Step 3: Determine output

    Since condition is true, the 'Pass' string is output.
  4. Final Answer:

    Pass -> Option B
  5. Quick Check:

    Negate false is true, and true and true is true [OK]
Quick Trick: Negate false to true, then -and with true yields true [OK]
Common Mistakes:
  • Ignoring operator precedence
  • Misunderstanding -not effect
  • Assuming output is Fail due to $x false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes