2013-07-09 71 views
4

我已經寫了一個需要bool參數的powershell腳本 我也有一個到此powershell腳本的窗口快捷方式。 問題是,無論何時我嘗試從快捷方式運行腳本,該參數都被解釋爲一個字符串,而不是一個布爾,腳本崩潰。將bool參數傳遞給powershell腳本快捷方式

這是我最初放置在我的快捷方式的目標部分:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" $true 

我搜索過的解決方案在線和嘗試了以下選項,以及:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" -copyAll:$true 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" -copyAll:`$$true 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" "`$$true" 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" `$$true 

和多個這樣的變化。

這是我的問題給你:有沒有辦法從Windows快捷方式運行一個bool參數的值發送到腳本?

回答

4

嘗試這樣的:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& 'C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1'" -copyAll:$true 
-file參數

傳遞bool到腳本嘗試的開關參數:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" {-All:$False} 

最後一個是從TechNet抽放,但說實話,我將永遠無法使用它。

+0

對不起,但程序文件中的空間與命令混淆它只是試圖運行腳本c:\ Program並認爲其餘的路徑是一個參數,而對於你的第二種方法,我有以下錯誤: '1'char:137 + C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe -File「C:\ Program Files \ MySoftware \ diagnostic \ DiagnosticTool」。 ps1「{ - <<<< All:$ true} + CategoryInfo:ParserError:( - :String)[],ParentContainsErrorRecordException + FullyQualifiedErrorId:MissingExpressionAfterOperator ' –

+0

@memoryofadream我編輯了我的第一個命令。試試吧。 –

+1

工作。非常感謝, 雖然我真的不知道在這種特殊情況下是什麼,但謝謝。 –