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
Default state: Disabled
Description
This rule detects functions where multiple parameters within the same parameter set are marked as
accepting pipeline input by value. Parameter sets should have at most one parameter with
ValueFromPipeline = true.
When you need multiple parameters to accept different types of pipeline input, use separate
parameter sets instead. Each parameter set can have its own single ValueFromPipeline parameter,
but you can't have more than one within the same parameter set.
Example
Noncompliant
function Process-Data {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[string] $InputData,
[Parameter(ValueFromPipeline)]
[string] $ProcessingMode
)
process {
Write-Output "$ProcessingMode`: $InputData"
}
}
Compliant
function Process-Data {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
[string] $InputData,
[Parameter(Mandatory)]
[string] $ProcessingMode
)
process {
Write-Output "$ProcessingMode`: $InputData"
}
}
Configure rule
Rules = @{
PSUseSingleValueFromPipelineParameter = @{
Enable = $true
}
}
Parameters
Enable
This parameter controls whether ScriptAnalyzer checks the code against this rule. It accepts a
boolean value. To enable this rule, set this parameter to $true. The default value is $false.
Suppression
This rule is disabled by default. If you have enabled it in your configuration but want to suppress
it for a specific function, you can use the SuppressMessage attribute:
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). - This rule doesn't flag parameters with
ValueFromPipeline = $false. - 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.