Bird
0
0

Given this function, what will be the output when piping numbers 1 to 3?

medium📝 Command Output Q13 of 15
PowerShell - Functions
Given this function, what will be the output when piping numbers 1 to 3?
function Show-Number {
  param([Parameter(ValueFromPipeline=$true)] $num)
  process { Write-Output ($num * 2) }
}
1..3 | Show-Number
ANo output
B2 4 6
C3 6 9
D1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand pipeline input and process block

    The function accepts pipeline input for parameter $num. The process block runs once per pipeline item.
  2. Step 2: Calculate output for each input

    Input numbers 1, 2, 3 are piped. Each is multiplied by 2 and output: 2, 4, 6.
  3. Final Answer:

    2 4 6 -> Option B
  4. Quick Check:

    Each input * 2 = output [OK]
Quick Trick: process block runs per item; multiply input by 2 [OK]
Common Mistakes:
  • Thinking process runs once for all items
  • Outputting original numbers instead of multiplied
  • No output due to missing pipeline input

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes