Skip to content

process-block-for-pipeline

PowerShellcorrectnessno fixdefault: offpowershell/psscriptanalyzer

Reports a function or script block with a parameter that has ValueFromPipeline or ValueFromPipelineByPropertyName and no process block. A filter counts as having one.

Without a process block the body runs once, after the pipeline has finished, and sees only the last object that came in. The others are lost.

To fix, put the work in process { }.

Reported
...
function Get-Alias { }
function Get-Series { }
function Get-Name {
param([Parameter(ValueFromPipeline)]$Item)
$Item
}
function Get-Name2 {
...
powershell:
lint:
rules:
process-block-for-pipeline: warn # off (default), warn, error

Enabled by the presets: powershell/psscriptanalyzer.

Suppress one line with sudsy-disable-next-line process-block-for-pipeline in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
psscriptanalyzer PSUseProcessBlockForPipelineCommand partial A process block anywhere in the function text counts, a nested one too.