GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add UseSingleValueFromPipelineParameter Rule by liamjpeters · Pull Request #2119 · PowerShell/PSScriptAnalyzer

Conversation

@liamjpeters

@liamjpeters Liam Peters (liamjpeters) commented Aug 9, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Summary

Adds a new rule, UseSingleValueFromPipelineParameter, which flags 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

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .cs, .ps1 and .psm1 files have the correct copyright header
  • Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@liamjpeters
Liam Peters (liamjpeters) requested review from Andy Jordan (andyleejordan), Christoph Bergmeister (bergmeister), Mikey Lombardi (He/Him) (michaeltlombardi) and Sean Wheeler (sdwheeler) as code owners August 9, 2025 12:47
@liamjpeters

Liam Peters (liamjpeters) commented Aug 14, 2025

Copy link
Copy Markdown
Contributor Author

Bodging a built version of this into VSCode, I think it makes sense to flag each parameter attributes so they all get a yellow squiggly. That said, if there's a way to emit a single DiagnosticRecord that has multiple extents, I'm happy to change it.

image
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liamjpeters Liam Peters (liamjpeters) changed the title Use single value from pipeline parameter Add UseSingleValueFromPipelineParameter Rule Aug 18, 2025
@andyleejordan

Andy Jordan (andyleejordan) commented Oct 13, 2025

Copy link
Copy Markdown
Member

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

You're right that most of the time someone does this, it's probably a mistake. But it is valid and there's a small use case of switching parameter sets based on the type of value received over the pipeline. So we can accept this as an optional rule, but it cannot be on by default.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andyleejordan
Andy Jordan (andyleejordan) suggested changes Oct 13, 2025
View reviewed changes
Comment thread docs/Rules/README.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

@liamjpeters

Liam Peters (liamjpeters) commented Oct 14, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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

You're right that most of the time someone does this, it's probably a mistake. But it is valid and there's a small use case of switching parameter sets based on the type of value received over the pipeline. So we can accept this as an optional rule, but it cannot be on by default.

Thanks so much for looking at this Andy 😀

I don't follow currently and I'm keen to. If you've the time to explain that use-case, I'd really appreciate that. If not, don't worry I'll get this changed to optional as you suggest.


The rule checks that, at most, one parameter per set accepts pipeline input by value (my comment ommited "set"). So, if you're changing parameter sets based on the pipeline input - that's fine, you'd still only be accepting value binding on one parameter in that set?

function Test-ValueFromPipeline {
    [CmdletBinding()]
    param (
        [Parameter(ParameterSetName = 'One', ValueFromPipeline)]
        [string]
        $Parameter1,
        [Parameter(ParameterSetName = 'Two', ValueFromPipeline)]
        [int]
        $Parameter2
    )
    process {
        "$($PSCmdlet.ParameterSetName) was used."
        "Parameter1: $Parameter1!"
        "Parameter2: $Parameter2!"
    }
}

'8' | Test-ValueFromPipeline

# One was used.
# Parameter1: 8!
# Parameter2: 0!

8 | Test-ValueFromPipeline

# Two was used.
# Parameter1: !
# Parameter2: 8!

When multiple parameters accept pipeline input by value - binding without and with type coercion is attempted for each. If the binding succeeds for multiple parameters then you have the same data bound to multiple parameters? I guess one parameter could be a string and another could be an int, bound by coercion if the string is a valid integer?

Is the use-case you're talking about when coercion for one such type would fail? e.g. An int and a Process

function Test-ValueFromPipeline {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline)]
        [System.Diagnostics.Process]
        $Parameter1,
        [Parameter(ValueFromPipeline)]
        [int]
        $Parameter2
    )
    process {
        "Parameter1: $($Parameter1.Name)!"
        "Parameter2: $Parameter2!"
    }
}

Get-Process -Name 'Code' | Select -First 1 | Test-ValueFromPipeline

# Parameter1: Code!
# Parameter2: 0!

1990 | Test-ValueFromPipeline

# Parameter1: !
# Parameter2: 1990!

You'd then make some check about $Parameter1 having a value and go from there with whatever logic?

If that's the case, why would the use of parameter sets not be encouraged? The 32 set limit? Complexity?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andyleejordan

Andy Jordan (andyleejordan) commented Oct 15, 2025

Copy link
Copy Markdown
Member

Patrick Meinecke (@SeeminglyScience) has the explanation (I was relaying it from a triage call).

liamjpeters reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@liamjpeters
Liam Peters (liamjpeters) force-pushed the UseSingleValueFromPipelineParameter branch from 0abeb30 to 834059d Compare October 23, 2025 18:12
@bergmeister
Christoph Bergmeister (bergmeister) requested a review from a team as a code owner January 30, 2026 17:07
bergmeister
Christoph Bergmeister (bergmeister) approved these changes Jan 30, 2026
View reviewed changes

@bergmeister Christoph Bergmeister (bergmeister) left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, happy to have it. Looks OK overall

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

liamjpeters reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/Rules/UseSingleValueFromPipelineParameter.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Rules/UseSingleValueFromPipelineParameter.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) approved these changes Feb 2, 2026
View reviewed changes
Liam Peters (liamjpeters) and others added 6 commits February 19, 2026 08:55
@liamjpeters
Added Rule UseSingleValueFromPipelineParameter
294aaed
@liamjpeters
Correct rule name for consistency and to fix failing docs tests
bdc6903
@liamjpeters
Update handling of empty AST passed to AnalyzeScript
90c3027
@liamjpeters
Fixup built-in rule count test
dd3d001
@liamjpeters
Make rule not enabled by default
8e47368
@liamjpeters @bergmeister
Apply suggestions from code review
7b2667a
Co-authored-by: Christoph Bergmeister <[email protected]>
@liamjpeters
Liam Peters (liamjpeters) force-pushed the UseSingleValueFromPipelineParameter branch from d77965e to 7b2667a Compare February 19, 2026 08:55
Christoph Bergmeister (bergmeister) and others added 2 commits February 19, 2026 16:45
@bergmeister
Merge branch 'main' into UseSingleValueFromPipelineParameter
4bda72b
@andyleejordan
Merge branch 'main' into UseSingleValueFromPipelineParameter
9c16ddf
andyleejordan
Andy Jordan (andyleejordan) approved these changes Mar 17, 2026
View reviewed changes

@andyleejordan Andy Jordan (andyleejordan) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andyleejordan

Andy Jordan (andyleejordan) commented Mar 17, 2026

Copy link
Copy Markdown
Member

Whelp, the auto accept-combined merge was incorrect (it looked right). Liam Peters (@liamjpeters) are you able to rebase this or otherwise fix the merge conflict?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Andy Jordan (andyleejordan) added 2 commits March 18, 2026 13:06
@andyleejordan
Fix merge
f0bf03f
@andyleejordan
Merge branch 'main' into pr/liamjpeters/2119
79961aa
@andyleejordan
Andy Jordan (andyleejordan) enabled auto-merge (squash) March 18, 2026 20:08
@liamjpeters

Liam Peters (liamjpeters) commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

Andy Jordan (@andyleejordan) My hero ❤️. Thanks for sorting that out - I didn't get time to look at it yesterday

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bergmeister
Christoph Bergmeister (bergmeister) approved these changes Mar 19, 2026
View reviewed changes
@andyleejordan
Andy Jordan (andyleejordan) merged commit 669c685 into PowerShell:main Mar 19, 2026
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bergmeister Christoph Bergmeister (bergmeister) bergmeister approved these changes
@sdwheeler Sean Wheeler (sdwheeler) Awaiting requested review from sdwheeler
@michaeltlombardi Mikey Lombardi (He/Him) (michaeltlombardi) Awaiting requested review from michaeltlombardi michaeltlombardi is a code owner
+1 more reviewer
@andyleejordan Andy Jordan (andyleejordan) andyleejordan approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@liamjpeters @andyleejordan @bergmeister
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.