我写了一个带有 bool 参数的 powershell 脚本
我也有这个 powershell 脚本的 Windows 快捷方式。
问题是,每当我尝试从快捷方式运行脚本时,参数都会被解释为字符串,而不是 boolean 值,并且脚本会崩溃。
这是我最初放置在快捷方式目标部分下的内容:
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 快捷方式运行 a 时,有没有办法将 bool 参数的值发送到脚本?
最佳答案
试试这个:
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但说实话,我永远无法使用它。
关于powershell - 将 bool 参数传递给 powershell 脚本快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17547200/