バッチ ファイルから PowerShell スクリプトを呼び出す必要があります。スクリプトの引数の 1 つはブール値です。
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -File .\RunScript.ps1 -Turn 1 -Unify $false
コマンドは次のエラーで失敗します:
Cannot process argument transformation on parameter 'Unify'. Cannot convert value "System.String" to type "System.Boolean", parameters of this type only accept booleans or numbers, use $true, $false, 1 or 0 instead.
At line:0 char:1
+ <<<< <br/>
+ CategoryInfo : InvalidData: (:) [RunScript.ps1], ParentContainsErrorRecordException <br/>
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,RunScript.ps1
現在、スクリプト内で文字列からブール値への変換を使用しています。しかし、ブール値の引数を PowerShell に渡すにはどうすればよいでしょうか?
ベストアンサー1
より明確な使用法としては、代わりにスイッチ パラメータを使用することです。その場合、Unify パラメータが存在するだけで、それが設定されていることを意味します。
そのようです:
param (
[int] $Turn,
[switch] $Unify
)