I'm trying to run a PowerShell Script from a .cmd File. Here are the script parameters I've defined:
Param(
[string]$Customer,
[string]$EntryPointINT,
[string]$EntryPointPRD,
[string]$EntryPointVDI,
[string]$LicenseServer,
[bool]$onlyVDI,
[bool]$hasVDI,
[int]$insertHelper
)
So as you see, onlyVDI and hasVDI are from the type bool. So far so good. When I start the script from the PowerShell console I can do the following thing (changed customername and the servername here):
.\kpi.ps1 -Customer "CustName" -EntryPointVDI "servername" -onlyVDI 0 -hasVDI 1 -insertHelper 1
This works perfectly as intended. So now I want to start the same script from a .cmd file. It looks like the following:
powershell.exe -File %~dp0%kpi.ps1 -Customer "Custname" -EntryPointVDI "servername" -LicenseServer "sc005019" -onlyVDI 0 -hasVDI 0 -insertHelper 1
This results in the following error:
C:\***\***\***\kpi.ps1 : Cannot process argument transformation on parameter
'onlyVDI'. Cannot convert value "System.String" to type "System.Boolean".
Boolean parameters accept only Boolean values and numbers, such as $True,
$False, 1 or 0.
+ CategoryInfo : InvalidData: (:) [kpi.ps1], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,cop_kpi.ps1
Can someone explain me why the 0 on onlyVDI is a string? I've tried everything, tried to replace it with $False ... can't get it to work. Right now I've defined it as a string in the PowerShell Script and pass it as a string from the cmd file, it works as a workaround, but it isn't clean. I would like to get it running with the [bool] datatype.