Home Dashboard Directory Help
Search

Switch parameter not converted to correct type by PSMakovec


Status: 

Active


4
3
Sign in
to vote
Type: Bug
ID: 793973
Opened: 7/15/2013 6:02:43 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

Having this function:

function Test-SwitchParam
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$true)]
        [switch]$Win
    )
    $Win
}

When I will not provide switch from cmdline and provide it later, will receive this:

Test-SwitchParam
cmdlet Test-SwitchParam at command pipeline position 1
Supply values for the following parameters:
Win: $true
Test-SwitchParam : Cannot process argument transformation on parameter 'Win'. Cannot convert value "System.String" to type "System.Management.Automation.SwitchParameter". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.
At line:1 char:1
+ Test-SwitchParam
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo         : InvalidData: (:) [Test-SwitchParam], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Test-SwitchParam

Even when I provide $true, $false, 0, 1 - it's not converted to switch so I can't provide it this way.
Details
Sign in to post a comment.
Sign in to post a workaround.