Thanks for your response Lee. I filed 183738 at your recommendation.
Interestingly enough, it appears that I'm getting different results by
removing the parameter set names. I had to remove the mandatory attribute
from the "-C" parameter, otherwise Powershell always required the "-C"
parameter. The first example is a repeat of the original problem to show
the mandatory attribute didn't change the behavior.
This feels like it is degrading to the 183738 problem since it revolves all
parameter sets.
Thanks, Alan
===========================================
===========================================
[Cmdlet("Test", "Parameter", SupportsShouldProcess = true) ]
public class TestParameterCommand : PSCmdlet
{
[Parameter( ParameterSetName = "FOO", Mandatory = true ) ]
[Parameter( ParameterSetName = "BAR", Mandatory = true ) ]
public string A { get { return a; } set { a = value; } }
private string a;
[Parameter( ParameterSetName = "FOO", Mandatory = true ) ]
[Parameter( ParameterSetName = "BAR", Mandatory = true ) ]
public string B { get { return b; } set { b = value; } }
private string b;
[Parameter( ParameterSetName = "BAR" ) ]
public string C { get { return c; } set { c = value; } }
private string c;
}
PS C:\> Test-Parameter -A abc -B 123 -C abc123
PS C:\> Test-Parameter -A abc -B 123
Test-Parameter : Parameter set cannot be resolved using the specified named
parameters.
At line:1 char:15
+ Test-Parameter <<<< -A abc -B 123
PS C:\>
===========================================
===========================================
[Cmdlet("Test", "Parameter", SupportsShouldProcess = true) ]
public class TestParameterCommand : PSCmdlet
{
[Parameter(Mandatory = true ) ]
public string A { get { return a; } set { a = value; } }
private string a;
[Parameter( Mandatory = true ) ]
public string B { get { return b; } set { b = value; } }
private string b;
[Parameter( ParameterSetName = "BAR" ) ]
public string C { get { return c; } set { c = value; } }
private string c;
}
PS C:\> Test-Parameter -A abc -B 123 -C abc123
PS C:\> Test-Parameter -A abc -B 123
PS C:\>
"Lee Holmes [MSFT]" <lee.holmes@online.microsoft.com> wrote in message
news:%23UFrypywGHA.428@TK2MSFTNGP03.phx.gbl...
> For your earlier post, this seems to be a bug. Could you please file it
on
> the connect site?
>
> As for what you're running into now, your parameter sets are ambiguous.
> PowerShell can't tell whether the user has incompletely supplied the
> arguments to parameter set "BAR", or whether they've fully specified
"FOO".
>
> Does it work if you remove the parameter set names from A and B, but leave
> the parameter set name on C?
>
> Lee
>
> "Alan Taylor" <alan DOT ML @T geemail D_OT com> wrote in message
> news:eRxbuviwGHA.1304@TK2MSFTNGP06.phx.gbl...
> > I'm still scratching my head. In fact here is another parameter set
that
> > doesn't seem to work like I would expect it. If I give the runtime a
hint
> > with DefaultParameterSetName="FOO" this example works, but I shouldn't
> > have
> > to do that. The real set of parameters that I'm trying to make work is
> > more
> > complicated. The DefaultParameterSetName workaround will not work in
that
> > case.
> >
> > Does anyone have insight into why I'm not seeing parameter set "FOO" in
> > this
> > example? I'm also confused on the original question if anyone knows
what
> > is
> > going on there.
> >
> > Thanks, Alan
> >
> > [Cmdlet("Test", "Parameter", SupportsShouldProcess = true) ]
> > public class TestParameterCommand : PSCmdlet
> > {
> > [Parameter( ParameterSetName = "FOO", Mandatory = true ) ]
> > [Parameter( ParameterSetName = "BAR", Mandatory = true ) ]
> > public string A { get { return a; } set { a = value; } }
> > private string a;
> >
> > [Parameter( ParameterSetName = "FOO", Mandatory = true ) ]
> > [Parameter( ParameterSetName = "BAR", Mandatory = true ) ]
> > public string B { get { return b; } set { b = value; } }
> > private string b;
> >
> > [Parameter( ParameterSetName = "BAR", Mandatory = true ) ]
> > public string C { get { return c; } set { c = value; } }
> > private string c;
> > }
> >
> > //
> > // Why doesn't the "Test-Parameter -A abc -B 123" command parse?
> > // I was expecting Parameter Set Name "FOO"
> > //
> >
> > PS C:\> Test-Parameter -A abc -B 123 -C abc123
> > PS C:\> Test-Parameter -A abc -B 123
> > Test-Parameter : Parameter set cannot be resolved using the specified
> > named
> > parameters.
> > At line:1 char:15
> > + Test-Parameter <<<< -A abc -B 123
> > PS C:\>
> >
> >
> >
> >
> >
> >
> > "Alan Taylor" <alan DOT ML @T geemail D_OT com> wrote in message
> > news:uhw%23MWTwGHA.3936@TK2MSFTNGP04.phx.gbl...
> >> In the example below, I'm confused when the "-e" parameter is marked
> >> ambiguous. I have to specify all parameter set names for the command
to
> >> correctly parse. Is this a bug or intended behavior?
> >>
> >> [Cmdlet("Test", "Parameter", SupportsShouldProcess = true) ]
> >> public class TestParameterCommand : PSCmdlet
> >> {
> >> [Parameter( ParameterSetName = "A_C", Mandatory = true ) ]
> >> [Parameter( ParameterSetName = "A_D", Mandatory = true ) ]
> >> public string A { get { return a; } set { a = value; } }
> >> private string a;
> >>
> >> [Parameter( ParameterSetName = "B_C", Mandatory = true ) ]
> >> [Parameter( ParameterSetName = "B_D", Mandatory = true ) ]
> >> public string B { get { return b; } set { b = value; } }
> >> private string b;
> >>
> >> [Parameter( ParameterSetName = "A_C", Mandatory = true ) ]
> >> [Parameter( ParameterSetName = "B_C", Mandatory = true ) ]
> >> public string C { get { return c; } set { c = value; } }
> >> private string c;
> >>
> >> [Parameter( ParameterSetName = "A_D", Mandatory = true ) ]
> >> [Parameter( ParameterSetName = "B_D", Mandatory = true ) ]
> >> public string D { get { return d; } set { d = value; } }
> >> private string d;
> >>
> >> public string E { get { return e; } set { e = value; } }
> >> private string e;
> >> }
> >>
> >>
> >> PS C:\> Test-Parameter -a foo -c bar
> >> PS C:\> Test-Parameter -a foo -d bar
> >> PS C:\> Test-Parameter -b foo -c bar
> >> PS C:\> Test-Parameter -b foo -d bar
> >> PS C:\> Test-Parameter -a foo -c bar -e oops
> >> Test-Parameter : Parameter cannot be processed because the parameter
name
> >> 'e' is ambiguous. Possible matches include: -
> >> ErrorAction -ErrorVariable.
> >> At line:1 char:15
> >> + Test-Parameter <<<< -a foo -c bar -e oops
> >> PS C:\>
> >>
> >> //
> >> // Change the definition of -e to include all parameter sets. Like
this:
> >> //
> >> // [Parameter( ParameterSetName = "A_C") ]
> >> // [Parameter( ParameterSetName = "A_D") ]
> >> // [Parameter( ParameterSetName = "B_C") ]
> >> // [Parameter( ParameterSetName = "B_D") ]
> >> // public string E { get { return e; } set { e = value; } }
> >> // private string e;
> >> //
> >> // The command parses the way I intended it.
> >> //
> >>
> >> PS C:\> Test-Parameter -a foo -c bar
> >> PS C:\> Test-Parameter -a foo -c bar -e oops
> >> PS C:\>
> >>
> >>
> >
> >
>
>