Bird
0
0

Why does the following function not receive any input when piped data is sent to it?

medium📝 Debug Q7 of 15
PowerShell - Functions
Why does the following function not receive any input when piped data is sent to it?
function Display-Data {
  param($Data)
  process { Write-Output $Data }
}
1,2,3 | Display-Data
ABecause the pipeline input must be assigned to a variable named 'Input'.
BBecause the process block is missing.
CBecause the function does not have a begin block.
DBecause the parameter lacks <code>ValueFromPipeline=$true</code> attribute.
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter attributes

    The parameter $Data does not have ValueFromPipeline=$true.
  2. Step 2: Effect of missing attribute

    Without this attribute, the function does not accept pipeline input.
  3. Final Answer:

    Because the parameter lacks ValueFromPipeline=$true attribute. -> Option D
  4. Quick Check:

    Parameter must have ValueFromPipeline=$true to accept pipeline input [OK]
Quick Trick: Parameter needs ValueFromPipeline=$true to accept pipeline input [OK]
Common Mistakes:
  • Assuming process block alone enables pipeline input
  • Thinking begin block is required for pipeline input
  • Believing parameter name must be 'Input'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes