Some issues with parameter sets

Product: PowerShell Universal
Version: 3.4.5

Here is a sample of the parameters with the sets I am testing.

[CmdletBinding(DefaultParameterSetName='Server')]
param(
    [Parameter(Mandatory)]
    # [Parameter(Mandatory, ParameterSetName = 'Server')]
    # [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    # [Parameter(Mandatory, ParameterSetName = 'Host')]
    [string]
    $Server,

    [Parameter(Mandatory)]
    # [Parameter(Mandatory, ParameterSetName = 'Server')]
    # [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    # [Parameter(Mandatory, ParameterSetName = 'Host')]
    [PSCredential]
    $PSCredential,

    [Parameter(Mandatory)]
    # [Parameter(Mandatory, ParameterSetName = 'Server')]
    # [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    # [Parameter(Mandatory, ParameterSetName = 'Host')]
    [string]
    $Region,

    [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    [string]
    $ClusterName,

    [Parameter(Mandatory, ParameterSetName = 'Host')]
    [string]
    $HostName
)

$Server

Issue with the above code is when running from the admin ui , it does not pick up the default parameter set
image

Here is the code changes that allow the admin UI to work.

[CmdletBinding(DefaultParameterSetName='Server')]
param(
    #[Parameter(Mandatory)]
    [Parameter(Mandatory, ParameterSetName = 'Server')]
    [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    [Parameter(Mandatory, ParameterSetName = 'Host')]
    [string]
    $Server,

    # [Parameter(Mandatory)]
    [Parameter(Mandatory, ParameterSetName = 'Server')]
    [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    [Parameter(Mandatory, ParameterSetName = 'Host')]
    [PSCredential]
    $PSCredential,

    # [Parameter(Mandatory)]
    [Parameter(Mandatory, ParameterSetName = 'Server')]
    [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    [Parameter(Mandatory, ParameterSetName = 'Host')]
    [string]
    $Region,

    [Parameter(Mandatory, ParameterSetName = 'Cluster')]
    [string]
    $ClusterName,

    [Parameter(Mandatory, ParameterSetName = 'Host')]
    [string]
    $HostName
)

$Server

Now I can pick each of the parameter set to run this script.

I see different issues with Invoke-PSUScript
The updated changes fail

Now I revert to the original version this happens

I changed from using the type [PSCredential] to [Object] , so it appears I cannot pass a [PSCredential] to a dynamic variable.

I feel this is a bug and wonder if I should report such.

  1. I cannot use parameter sets for a script that is called via invoke-psuscript
  2. I cannot use a PSCredential parameter as it complains: Unable to find type [PSCredential]

These certainly seem like bugs. I can open some issues for these items to see if we can get them resolved.

Tested in 3.5.2 today and it looks to be fixed.
Just cannot pass a PScredential which make sense and I can work around that.

Adam said a fix should be in for the PSCredential param issue this week in an issue I reported to him.