Skip to content

Latest commit

 

History

History
69 lines (54 loc) · 1.6 KB

File metadata and controls

69 lines (54 loc) · 1.6 KB
description Use process block for commands that accept input from a pipeline
ms.date 07/21/2026
ms.topic reference
title UseProcessBlockForPipelineCommand

UseProcessBlockForPipelineCommand

Severity Level: Warning

Default state: Always enabled

Description

This rule detects functions with pipeline-enabled parameters that handle input directly in the function body instead of using a process block. Functions that accept pipeline input through parameters should always process that input in a process block. Handling parameter input directly in the function body can lead to unexpected behavior because the function body executes once, while the process block executes for each object in the pipeline.

Example

Noncompliant

Function Get-Number
{
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipeline)]
        [int]
        $Number
    )

    $Number
}

Compliant

Function Get-Number
{
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipeline)]
        [int]
        $Number
    )

    process
    {
        $Number
    }
}

Configure rule

This rule is always enabled and isn't configurable. Use one of the following methods to avoid using this rule:

  • Create a custom rule configuration file to include only the rules you want or exclude the rules you don't want.
  • Add the appropriate rule suppression attributes to your code to suppress the rule for specific code blocks. For more information, see the Suppressing rules section of Using PSScriptAnalyzer.