Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 = $trueand implicitValueFromPipeline(which is the same as using= $true) - Parameters with
ValueFromPipeline=$falseare 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
ValueFromPipelineparameter without triggering this rule