Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
PowerShell - Working with Objects
Identify the error in this code snippet:
$nums = 1, 2, 3
$result = Measure-Object -Sum $nums
$result.Sum
ASum parameter is invalid
BVariable $nums is not defined
CMeasure-Object requires input via pipeline, not as argument
DSum property does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Check how Measure-Object receives input

    Measure-Object expects input objects through the pipeline, not as a direct argument.
  2. Step 2: Identify correct usage

    The correct syntax is $nums | Measure-Object -Sum. Passing $nums as a parameter causes an error.
  3. Final Answer:

    Measure-Object requires input via pipeline, not as argument -> Option C
  4. Quick Check:

    Input must be piped to Measure-Object [OK]
Quick Trick: Always pipe data into Measure-Object, don't pass as argument [OK]
Common Mistakes:
  • Passing array as argument
  • Misusing parameters
  • Expecting Sum property without calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes