Skip to main content

Documentation Index

Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt

Use this file to discover all available pages before exploring further.

powershell/PSUseSingleValueFromPipelineParameter is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.
PropertyValue
SeverityWarning
CategoryPSScriptAnalyzer
Auto-fixNo

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.

Examples

Problematic code

function Process-Data {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline)]
        [string] $InputData,

        [Parameter(ValueFromPipeline)]
        [string] $ProcessingMode
    )

    process {
        Write-Output "$ProcessingMode`: $InputData"
    }
}

Correct code

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

Source

This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for UseSingleValueFromPipelineParameter, licensed under CC BY 4.0.