mem*_*eam 4 parameters powershell boolean shortcut
我编写了一个带有bool参数的powershell脚本,我也有一个Windows快捷方式来访问该powershell脚本。问题是,每当我尝试从快捷方式运行脚本时,参数都会被解释为字符串而不是布尔值,并且脚本会崩溃。
这是我最初放在快捷方式的目标部分下的内容:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" $true
Run Code Online (Sandbox Code Playgroud)
我在线搜索了解决方案,并尝试了以下选项:
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
Run Code Online (Sandbox Code Playgroud)
以及多个这样的变化。
这是我的问题:从Windows快捷方式运行a时,是否可以将bool参数的值发送到脚本?
试试这个:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& 'C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1'" -copyAll:$true
Run Code Online (Sandbox Code Playgroud)
的with -file参数传递bool给脚本的switch参数的尝试:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Program Files\MySoftware\diagnostic\DiagnosticTool.ps1" {-All:$False}
Run Code Online (Sandbox Code Playgroud)
最后一个摘自TechNet,但老实说,我永远无法使用它。