Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmdlets in filePath that rely on parameter sets are not available in PowerShell 2 #22

Open
alx9r opened this issue Oct 3, 2015 · 0 comments

Comments

@alx9r
Copy link
Owner

alx9r commented Oct 3, 2015

PowerShell 2 isn't able to resolve parameter sets for some of the Cmdlets in filePath even though it should be able to. PowerShell 4 and later does not have this problem. The affected Cmdlets are simply not available when using PowerShell 2.

Here is the repro of the fundamental problem:

module.psm1

function f {
    [CmdletBinding()]
    param
    (
        [Parameter(ParameterSetName = 'A',
                   Mandatory        = $true)]
        $a,

        [Parameter(ParameterSetName = 'A',
                   Mandatory        = $true)]
        [Parameter(ParameterSetName = 'B',
                   Mandatory        = $true)]
        $ab

    )
    process
    {
        $PSCmdlet.ParameterSetName
    }
}

module.Tests.ps1

Import-Module module -Force

Describe f {
    It 'should use the "A" parameter set when both a and ab are provided.' {
        f -a 'a' -ab 'b' | Should be A
    }
    It 'should use the "B" parameter set when only ab is provided.' {
        f -ab 'b' | Should be B
    }
}

Results

The above tests pass in PowerShell 4. However, PowerShell 2 produces the following result:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant