Git Product home page Git Product logo

Comments (5)

netsec4u avatar netsec4u commented on June 12, 2024 1

Thank you for your help and information! It is greatly appreciated!

from powershell.

mklement0 avatar mklement0 commented on June 12, 2024

The immediate problem is that -String2 and -Type cannot be combined unambiguously, causing parameter binding to stop right there - your DynamicParam block is never called.

To at least eliminate the "parameter set cannot be resolved error", comment out the [Parameter()] attribute that contains ParameterSetName = 'DynamicA-String2' that decorates the $String2 parameter.

It looks like you can greatly reduce the number of parameter sets, which will likely also solve your problem.

from powershell.

netsec4u avatar netsec4u commented on June 12, 2024

In other words, dynamic parameters cannot be used to make a parameter set unambiguous, requiring the static parameters to unambiguously select a parameter set.

I was able to change the dynamic parameter to not set the ParameterSetName, which allowed for the reduction of parameter sets to resolve. However, I want to know if this was a bug or if it was by design. It sounds like it is by design.

from powershell.

mklement0 avatar mklement0 commented on June 12, 2024

In other words, dynamic parameters cannot be used to make a parameter set unambiguous, requiring the static parameters to unambiguously select a parameter set.

That's a great summary. Yes, any given static parameters must resolve unambiguously to a parameter set first.

While I cannot speak in any official capacity, I do think that this is by design, given the stages of parameter binding described by a team member in #14701 (comment) - also see the clarification in #14701 (comment).

Here's what I think is a minimal example:

function Test-AmbiguousParameter {
  [CmdletBinding(DefaultParameterSetName = 'Default')]
  param (
    [Parameter(Mandatory = $true, ParameterSetName = 'Default')]
    $A,

    [Parameter(Mandatory = $false, ParameterSetName = 'Other')]
    $B
  )

  DynamicParam {
    Write-Verbose -Verbose HERE
  }

  process {
    Write-Output $PSCmdlet.ParameterSetName
  }

}

Test-AmbiguousParameter -a 1 -b 2 predictably yields the "parameter set cannot be resolved" error and never prints the VERBOSE: HERE message, implying that the DynamicParam block is never invoked.

Contrast with Test-AmbiguousParameter -a 1 and Test-AmbiguousParameter -b 2

from powershell.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on June 12, 2024

📣 Hey @netsec4u, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

from powershell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.