Challenge - 5 Problems
Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this PowerShell function when piped?
Consider the following PowerShell function that accepts pipeline input. What will be the output when you run
1,2,3 | Test-PipelineInput?PowerShell
function Test-PipelineInput { param( [Parameter(ValueFromPipeline=$true)] [int]$Number ) process { $Number * 2 } } 1,2,3 | Test-PipelineInput
Attempts:
2 left
💡 Hint
Think about how pipeline input is processed in the process block.
✗ Incorrect
The function accepts each number from the pipeline one by one and multiplies it by 2, outputting each result on its own line.
💻 Command Output
intermediate2:00remaining
What error occurs when ValueFromPipeline is missing but pipeline input is sent?
Given this function without ValueFromPipeline set, what happens when you run
"apple","banana" | Test-NoPipeline?PowerShell
function Test-NoPipeline { [CmdletBinding()] param( [string]$Fruit ) process { Write-Output $Fruit } } "apple","banana" | Test-NoPipeline
Attempts:
2 left
💡 Hint
Check if the parameter allows pipeline input.
✗ Incorrect
Since the parameter does not have ValueFromPipeline set to true, PowerShell cannot bind pipeline input to it, causing a binding error.
🔧 Debug
advanced2:00remaining
Why does this function not output anything when piped?
Examine the function below. Why does
1,2,3 | Silent-Process produce no output?PowerShell
function Silent-Process { param( [Parameter(ValueFromPipeline=$true)] [int]$InputNumber ) process { $result = $InputNumber * 10 } } 1,2,3 | Silent-Process
Attempts:
2 left
💡 Hint
Check if the function outputs anything in the process block.
✗ Incorrect
The function calculates the value but does not output it. In PowerShell, expressions alone do not output unless explicitly output or returned.
📝 Syntax
advanced2:00remaining
Which function definition correctly accepts pipeline input by property name?
You want to accept pipeline input by matching the property name 'Name'. Which function parameter declaration is correct?
Attempts:
2 left
💡 Hint
ValueFromPipelineByPropertyName allows matching input object properties to parameters.
✗ Incorrect
Setting ValueFromPipelineByPropertyName to true allows the parameter to bind to pipeline input objects that have a matching property name.
🚀 Application
expert2:00remaining
How many items are output by this advanced pipeline function?
Given this function and pipeline, how many output items are produced?
PowerShell
function Complex-Pipeline { param( [Parameter(ValueFromPipeline=$true)] [int]$Num ) begin { $sum = 0 } process { $sum += $Num if ($Num % 2 -eq 0) { Write-Output $Num } } end { Write-Output $sum } } 1..5 | Complex-Pipeline
Attempts:
2 left
💡 Hint
Count outputs in process and end blocks.
✗ Incorrect
The process block outputs even numbers (2,4) so 2 outputs, plus the end block outputs the sum (15), total 3 outputs. But the question asks how many items are output, so 2 evens + 1 sum = 3 items.