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:
************************************
[CmdletBinding()]
param (
[parameter(Mandatory=$false)]
[string]$P1,
[parameter(Mandatory=$false)]
[string]$P2,
[parameter(Mandatory=$false)]
[string]$P3,
[parameter(Mandatory=$false)]
[switch]$S1,
[parameter(Mandatory=$false)]
[switch]$S2
)
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?