Bird
0
0

What will this PowerShell script output?

medium📝 Command Output Q13 of 15
PowerShell - Automation Patterns
What will this PowerShell script output?
1..3 | ForEach-Object { $_ * 2 }
A[1, 2, 3]
B[3, 6, 9]
C[2, 4, 6]
DError: Invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range operator

    1..3 creates a list of numbers 1, 2, and 3.
  2. Step 2: Apply ForEach-Object multiplication

    Each number is multiplied by 2, resulting in 2, 4, and 6.
  3. Final Answer:

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

    1..3 times 2 = [2, 4, 6] [OK]
Quick Trick: Multiply each number in the range by 2 [OK]
Common Mistakes:
  • Confusing range operator with array
  • Forgetting to multiply inside the loop
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes