Bird
0
0

Identify the error in this script:

medium📝 Debug Q14 of 15
PowerShell - Cmdlets and Pipeline
Identify the error in this script:
1..3 | ForEach-Object { Write-Output $item }
AForEach-Object cannot process number ranges
BMissing pipeline operator before ForEach-Object
CIncorrect use of Write-Output cmdlet
DVariable $item is undefined inside the script block
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage inside ForEach-Object

    Inside ForEach-Object, the current item is referenced by $_, not $item.
  2. Step 2: Verify other syntax elements

    The pipeline and Write-Output usage are correct, and ForEach-Object can process number ranges.
  3. Final Answer:

    Variable $item is undefined inside the script block -> Option D
  4. Quick Check:

    Use $_ for current item, not $item [OK]
Quick Trick: Use $_ inside ForEach-Object, not custom variable names [OK]
Common Mistakes:
  • Using undefined variables instead of $_
  • Forgetting the pipeline operator
  • Misunderstanding ForEach-Object capabilities

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes