[Solved] AmbiguousParameterSet error

So you decided to use the ParameterSet statement in your script or cmdlet.

But you get now the following error:

  • CategoryInfo          : InvalidArgument: (:) [<CmdletName|ScriptName>], ParameterBindingException
  • FullyQualifiedErrorId : AmbiguousParameterSet,<CmdletName|ScriptName>

The reason

You have this error in two situations:

  • Your command-line doesn’t use any of the parameters members of a parameter set.
  • Your command-line uses simultaneously two or more parameters members of different exclusive parameter sets.

  • The solution

    Two possibilities:

    • Use parameters member of only one parameter set.
  • Make your parameter a member of all needed parameter sets.
    You achieve this by using as many [Parameter()] statements as parameter sets the parameter needs to be a member of.
    For example, if you have three parameter sets and you want the parameter Username to be a member of the ParamSet1 and the ParamSet3 parameter sets.

  • [Parameter(ParameterSetName='ParamSet1')]
    [Parameter(ParameterSetName='ParamSet3')]
    $UserName
    

    More about

    About Functions Advanced Parameters (Microsoft Docs)

    Cmdlet Parameter Sets (MSDN)

    Leave a Reply

    Please log in using one of these methods to post your comment:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s