Skip to content

Use single value from pipeline parameter #2119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

liamjpeters
Copy link
Contributor

PR Summary

New rule to flag when multiple parameters in the same parameter set have ValueFromPipeline set to true.

When running something like:

function Test-ValueFromPipeline {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline)]
        [string]
        $Parameter1,
        [Parameter(ValueFromPipeline)]
        [string]
        $Parameter2
    )
    process {
        "Parameter1: $Parameter1!"
        "Parameter2: $Parameter2!"
    }
}

"Value1" | Test-ValueFromPipeline

I don't get any kind of error or warning, which I was surprised by.

Consistent behaviour across both 5.1 and 7.4.11.

Multiple parameters accepting pipeline input by value doesn't make sense (to me at least - maybe I'm missing a use-case?).

The above outputs:

Parameter1: Value1!
Parameter2: Value1!

Both parameters get the pipeline input bound.

Parameter [Parameter2] PIPELINE INPUT ValueFromPipeline NO COERCION
BIND arg [Value1] to parameter [Parameter2]
    Executing DATA GENERATION metadata: [System.Management.Automation.ArgumentTypeConverterAttribute]
        result returned from DATA GENERATION: Value1
    BIND arg [Value1] to param [Parameter2] SUCCESSFUL
Parameter [Parameter1] PIPELINE INPUT ValueFromPipeline NO COERCION
BIND arg [Value1] to parameter [Parameter1]
    Executing DATA GENERATION metadata: [System.Management.Automation.ArgumentTypeConverterAttribute]
        result returned from DATA GENERATION: Value1
    BIND arg [Value1] to param [Parameter1] SUCCESSFUL

PR Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant