Error binding parameters in PowerShell

I have this PowerShell cmdlet:

function Test-ParameterBinding {
    #
    # .SYNOPSIS
    # Tests parameter binding.
    #
    [CmdletBinding()]
    param (    

        [Parameter(ParameterSetName = 's1', Mandatory = $true)]
        [int] $P1,

        [Parameter(ParameterSetName = 's1')]
        [Parameter(ParameterSetName = 's2', Mandatory = $true)]
        [string] $P2,

        [Parameter(ParameterSetName = 's1')]
        [Parameter(ParameterSetName = 's3', Mandatory = $true)]
        [bool] $P3
    )
    process { $PSCmdlet }
}

And here is the help for this cmdlet:

SYNTAX
    Test-ParameterBinding -P1 <Int32> [-P2 <String>] [-P3 <Boolean>] [<Com…

    Test-ParameterBinding -P2 <String> [<CommonParameters>]

    Test-ParameterBinding -P3 <Boolean> [<CommonParameters>]

Looking at the code and help, I would think that I could use a cmdlet like this:

Test-ParameterBinding -P2 'Bind to param set s2'
Test-ParameterBinding -P3 $true # Bind to param set s3

But for both of them I get:

Parameter set cannot be resolved using the specified named parameters.

Question 1: If the PowerShell will be able to communicate with the parameter sets s2, and s3in my two cases?

This means that there was no time to implement it for PowerShell version 2, or they did not find this problem.

Question 2: Is there something wrong with my reasoning here? If in these cases the parameter binding error fails?


I found something that could be directly related to my problem here in the PowerShell documentation :

, Windows PowerShell , . Windows PowerShell , . , , a, , , FileInfo , Windows PowerShell , , , . , , Windows PowerShell .

+5
1

, Powershell , .

, Powershell v2 . , , Powershell v3, , / 2.

+4

All Articles