February 2019
Intermediate to advanced
626 pages
15h 51m
English
The end block executes after process has acted on all objects in the input pipeline.
The end block cannot use the $_ automatic variable. Parameters that accept pipeline input will be filled with the last value from the process block:
function Show-Pipeline { begin { $position = $myinvocation.PipelinePosition Write-Host "Pipeline position ${position}: Start" } process { Write-Host "Pipeline position ${position}: $_" $_ } end { Write-Host "Pipeline position ${position}: End" }}
Running this command in a pipeline shows the end executing after all items in the input pipeline have been processed:
PS> $result = 1..2 | Show-PipelinePipeline position 1: StartPipeline position 1: 1Pipeline position 1: 2Pipeline position 1: End
Commands that make ...
Read now
Unlock full access