Switch parameter not converted to correct type - by PSMakovec

Status : 

 


5
3
Sign in
to vote
ID 793973 Comments
Status Active Workarounds
Type Bug Repros 1
Opened 7/15/2013 6:02:43 AM
Access Restriction Public

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.
Sign in to post a comment.