> ## 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

> Use at most a single ValueFromPipeline parameter per parameter set.

`powershell/PSUseSingleValueFromPipelineParameter` is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in Dockerfiles.

| Property | Value            |
| -------- | ---------------- |
| Severity | Warning          |
| Category | PSScriptAnalyzer |
| Auto-fix | No               |

## 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

```powershell theme={null}
function Process-Data {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline)]
        [string] $InputData,

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

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

### Correct code

```powershell theme={null}
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:

```powershell theme={null}
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:

```powershell theme={null}
[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](https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/blob/main/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseSingleValueFromPipelineParameter.md),
licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
