Skip to content

Latest commit

 

History

History
101 lines (79 loc) · 2.54 KB

File metadata and controls

101 lines (79 loc) · 2.54 KB
description ms.date ms.topic title
Use at most a single ValueFromPipeline parameter per parameter set.
08/08/2025
reference
UseSingleValueFromPipelineParameter

UseSingleValueFromPipelineParameter

Severity Level: Warning

Description

Parameter sets should have at most one parameter marked as ValueFromPipeline = true.

This rule identifies functions where multiple parameters within the same parameter set have ValueFromPipeline set to true (either explicitly or implicitly).

How

Ensure that only one parameter per parameter set accepts pipeline input by value. If you need multiple parameters to accept different types of pipeline input, use separate parameter sets.

Example

Wrong

function Process-Data {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline)]
        [string] $InputData,
        
        [Parameter(ValueFromPipeline)]
        [string] $ProcessingMode
    )
    
    process {
        Write-Output "$ProcessingMode`: $InputData"
    }
}

Correct

function Process-Data {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline)]
        [string] $InputData,
        
        [Parameter(Mandatory)]
        [string] $ProcessingMode
    )
    process {
        Write-Output "$ProcessingMode`: $InputData"
    }
}

Suppression

To suppress this rule for a specific parameter set, use the SuppressMessage attribute with the parameter set name:

function Process-Data {
    [Diagnostics.CodeAnalysis.SuppressMessage('PSUseSingleValueFromPipelineParameter', 'MyParameterSet')]
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline, ParameterSetName='MyParameterSet')]
        [string] $InputData,
        
        [Parameter(ValueFromPipeline, ParameterSetName='MyParameterSet')]
        [string] $ProcessingMode
    )
    process {
        Write-Output "$ProcessingMode`: $InputData"
    }
}

For the default parameter set, use 'default' as the suppression target:

[Diagnostics.CodeAnalysis.SuppressMessage('PSUseSingleValueFromPipelineParameter', 'default')]

Notes

  • This rule applies to both explicit ValueFromPipeline = $true and implicit ValueFromPipeline (which is the same as using = $true)
  • Parameters with ValueFromPipeline=$false are not flagged by this rule
  • The rule correctly handles the default parameter set (__AllParameterSets) and named parameter sets
  • Different parameter sets can each have their own single ValueFromPipeline parameter without triggering this rule