Bird
0
0

Identify the error in this script snippet:

medium📝 Debug Q6 of 15
PowerShell - Variables and Data Types
Identify the error in this script snippet:
1..3 | ForEach-Object { Write-Output "Item: $" }
AMissing underscore after $ to reference current object
BIncorrect use of Write-Output inside pipeline
CRange operator 1..3 is invalid
DForEach-Object requires parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Check variable usage inside string

    The script uses "$" instead of "$_"; $_ is needed to reference the current pipeline object.
  2. Step 2: Verify other syntax elements

    Write-Output is valid inside pipeline, 1..3 is valid range, and ForEach-Object uses braces correctly.
  3. Final Answer:

    Missing underscore after $ to reference current object -> Option A
  4. Quick Check:

    Use $_ to access current pipeline item [OK]
Quick Trick: Always use $_, not just $, for current pipeline item [OK]
Common Mistakes:
  • Using $ instead of $_ inside pipeline
  • Thinking Write-Output is invalid here
  • Misunderstanding range operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes