Passing switch arguments from a Batch file to powershell will not work

by Jul 12, 2013

Hi guys,

I want to start a powershell script with a large number of parameters via a batch file.

So I have created a very small script to show my problem I have. I want to run the the powershell script:


param (




Write-Host "P1: $P1"
Write-Host "P2: $P2"
Write-Host "P3: $P3"
Write-Host "S1: $S1"
Write-Host "S2: $S2"


I want to start the powershell script with the following batch file:


powershell.exe -ExecutionPolicy bypass -file T:CollectHwAndSwInfoTestScript.ps1 -P1 param1 -P2 param2 -P3 param3 -S1:0


All is ok until I want to use one of my switch parameters. In this case I get the error message that it is not possible to convert the paramter S1 from a system.string to a "System.Management.Automation.SwitchParameter" object.

I have already tried what I have found in the internet but no solution was solving my problem. Can anyone help me?