Steps to reproduce
function foo {
[cmdletbinding()]
Param([parameter(ValueFromPipeline)]$a)
Begin {1}
Process {2}
End {3}
}
Write-Host -ForegroundColor Green 'Expected:'
1..3|foo|%{$_} -pv x -ov y |select {$x},{$_},{$y}|out-host
Write-Host -ForegroundColor Green 'Actual:'
1..3|foo -pv x -ov y |select {$x},{$_},{$y}|out-host
Output:
Expected:
$x $_ $y
-- -- --
1 1 1
2 2 {1, 2}
2 2 {1, 2, 2}
2 2 {1, 2, 2, 2}
3 3 {1, 2, 2, 2…}
Actual:
$x $_ $y
-- -- --
1 1 1
2 {1, 2}
2 {1, 2, 2}
2 {1, 2, 2, 2}
3 {1, 2, 2, 2…}
Expected behavior
All output produced in any block (Begin, Process, or End) should be assigned to the PipelineVariable as it enters the pipeline. -OutVariable appears to behave correctly, i.e. it captures output that -PipelineVariable does not.
Actual behavior
Only output produced by the first block to exectute, and only on the first execution of that block is assigned to the PipelineVariable.
Examples:
- if a Begin block exists, the output from the Begin block will be assigned, but the output from the Process and End blocks will not.
- if a Begin block does not exists, the output from the first execution of the Process block will be assigned, but the output from subsequent executions of the Process block will not, and the output of the End block will not.
In the wild, on 5.1:
https://stackoverflow.com/questions/45782372/powershell-advanced-function-output-pipelinevariable-doesnt-work
https://www.reddit.com/r/PowerShell/comments/doboko/support_for_pipelinevariable_in_advanced_function/
Environment data
Name Value
---- -----
PSVersion 7.0.0-preview.5
PSEdition Core
GitCommitId 7.0.0-preview.5
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Steps to reproduce
Output:
Expected behavior
All output produced in any block (Begin, Process, or End) should be assigned to the PipelineVariable as it enters the pipeline. -OutVariable appears to behave correctly, i.e. it captures output that -PipelineVariable does not.
Actual behavior
Only output produced by the first block to exectute, and only on the first execution of that block is assigned to the PipelineVariable.
Examples:
In the wild, on 5.1:
https://stackoverflow.com/questions/45782372/powershell-advanced-function-output-pipelinevariable-doesnt-work
https://www.reddit.com/r/PowerShell/comments/doboko/support_for_pipelinevariable_in_advanced_function/
Environment data