February 2019
Intermediate to advanced
626 pages
15h 51m
English
The content of the process block runs once for each value received from the pipeline. The built-in $_ variable may be used to access objects in the pipeline within the process block:
function Show-Pipeline { begin { $position = $myinvocation.PipelinePosition Write-Host "Pipeline position ${position}: Start" } process { Write-Host "Pipeline position ${position}: $_" $_ }}
When an object is passed to the pipeline, the start message will be shown before the numeric value:
PS> $result = 1..2 | Show-PipelinePipeline position 1: StartPipeline position 1: 1Pipeline position 1: 2
Adding Show-Pipeline to the end of the pipeline will show that begin executes twice before process runs:
PS> $result = 1..2 | Show-Pipeline | Show-PipelinePipeline ...
Read now
Unlock full access