#Requires -PSEdition Core # HT @santisq in powershell-slack # https://powershell.slack.com/archives/C1RCWRDL4/p1685120926413089 function foo { param( [Parameter(Mandatory,ValueFromPipeline)] [string] $bar ) begin { $ScriptBlock = {"input is $_"; Start-Sleep 5} $pipe = { ForEach-Object -Parallel $ScriptBlock }.GetSteppablePipeline() $pipe.Begin($PSCmdlet) } process { $pipe.Process($bar) } end { $pipe.End() } } $foo = @('a','b','c') Measure-Command {$foo | foo} | select TotalSeconds Measure-Command {foo $foo} | select TotalSeconds