How to pass boolean values to a PowerShell script from a command prompt

問題:

I have to invoke a PowerShell script from a batch file. 我必須從批處理文件調用PowerShell腳本。 One of the arguments to the script is a boolean value: 腳本的參數之一是布爾值:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -File .\RunScript.ps1 -Turn 1 -Unify $false

The command fails with the following error: 該命令失敗,並顯示以下錯誤:

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

As of now I am using a string to boolean conversion inside my script. 到目前爲止,我正在腳本中使用字符串將布爾值轉換爲布爾值。 But how can I pass boolean arguments to PowerShell? 但是如何將布爾參數傳遞給PowerShell?


解決方案:

參考: https://stackoom.com/en/question/LJO1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章