Using the following example function:
Function Test {
param(
[Parameter(Position=0)]
[string]$Optional="some optional string",
[Parameter(Position=1, Mandatory=$true)]
[string]$Required
)
Process { }
}
I would expect the following to be identical:
Test -Optional "optional" "required"
and
Test "required"
It's not, but why? The optional parameter is not mandatory, but the second example will fail saying:
Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.
It seems natural that if only one parameter is specified, that it would be the mandatory parameter because it needs to be specified.
Is there any way to accomplish what I am trying to do?