I have a script foo.ps1
and a batch file foo.cmd
used to launch the script by double clicking the cmd file in file explorer.
The script accepts a switch parameter, but I don't know how to provide this kind of parameter. Simple parameters are ok.
Foo.ps1:
param(
[Parameter()]
[Switch]$MySwitch,
[Parameter()]
[string]$Name
)
Write-Host "`$MySwitch : $MySwitch, `$Name : $name"
Foo.cmd:
Powershell -noprofile -NonInteractive -file "%~dp0\foo.ps1" -Name "abc"
If I call the script with only "Name", it works. But If I specify MySwitch, it stops to work:
Foo2.cmd:
Powershell -noprofile -NonInteractive -File "%~dp0\foo.ps1" -Name "abc" -MySwitch:$false
The error is:
C:\temp\foo.ps1 : Impossible de traiter la transformation d'argument sur le paramètre «MySwitch». Impossible de convertir la valeur «System.String» en type « System.Management.Automation.SwitchParameter». Les paramètres booléens acceptent seulement des valeurs booléennes et des nombres, tels que $True, $False, 1 ou 0.
+ CategoryInfo : InvalidData : (:) [foo.ps1], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,foo.ps1