July 2018
Beginner
552 pages
13h 18m
English
Enabling your functions to accept pipeline input can make them much more powerful. That is also possible by using the parameter attribute.
The mandatory component that you need to use is a script block called process. This block is executed for each element flowing down the pipeline. The following code sample shows how entire objects are passed down the pipeline:
function pipelineByValue{ param ( [Parameter(ValueFromPipeline)] [string] $Parameter ) begin { $count = 0 } process { $count ++ Write-Host $Parameter } end { Write-Host "$count values processed" }}"a","b","c" | pipelineByValue
Accepting the pipeline input by value means that entire objects are bound to a parameter.
If the pipeline input is accepted by property name, ...
Read now
Unlock full access