Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - Operators
What will be the output of this PowerShell code?
$a = 7
$b = 5
if ($a -gt 5 -and $b -lt 10) { 'True' } else { 'False' }
ATrue
BFalse
CError
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate each condition

    $a -gt 5 is true (7 > 5), $b -lt 10 is true (5 < 10).
  2. Step 2: Apply '-and' operator

    Both conditions true, so '-and' returns true, executing 'True'.
  3. Final Answer:

    True -> Option A
  4. Quick Check:

    Both true with '-and' = True [OK]
Quick Trick: Both conditions must be true for '-and' to output true [OK]
Common Mistakes:
  • Assuming '-and' acts like '-or'
  • Misreading comparison operators
  • Expecting error due to syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes