Bird
0
0

What will be the output of this command?

medium📝 Command Output Q13 of 15
PowerShell - Cmdlets and Pipeline
What will be the output of this command?
1..5 | Where-Object { $_ % 2 -eq 0 }
A[1, 3, 5]
B[1, 2, 3, 4, 5]
C[2, 4]
DError: Invalid operator
Step-by-Step Solution
Solution:
  1. Step 1: Understand the input and condition

    The input is numbers 1 to 5. The condition filters numbers where remainder when divided by 2 equals 0 (even numbers).
  2. Step 2: Apply the condition to each number

    Numbers 2 and 4 satisfy the condition (2 % 2 = 0, 4 % 2 = 0). Others do not.
  3. Final Answer:

    [2, 4] -> Option C
  4. Quick Check:

    Filter even numbers = [2, 4] [OK]
Quick Trick: Use modulo (%) to filter even numbers [OK]
Common Mistakes:
  • Confusing even and odd numbers
  • Expecting all numbers as output
  • Thinking syntax causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes