我写了一个带有bool参数的powershell脚本 我还有一个这个powershell脚本的Windows快捷方式。 问题是,每当我尝试从快捷方式运行脚本时,参数都被解释为字符串,而不是bool,并且脚本崩溃。
这是我最初放在我的快捷方式的目标部分下面的内容:
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参数的值发送到脚本?
答案 0 :(得分:4)
试试这个:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& 'C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1'" -copyAll:$true
带有-file
参数的将bool
传递给脚本的switch参数尝试:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" {-All:$False}
最后一个是从TechNet开始的,但说实话,我永远无法使用它。