将bool参数传递给powershell脚本快捷方式



我已经编写了一个powershell脚本,它接受bool参数我还有一个指向这个powershell脚本的windows快捷方式。问题是,每当我试图从快捷方式运行脚本时,参数都会被解释为字符串,而不是布尔,脚本就会崩溃。

这是我最初放在快捷方式目标部分下的内容:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -File "C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1" $true

我在网上搜索了解决方案,并尝试了以下选项:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -File "C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1" -copyAll:$true
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -File "C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1" -copyAll:`$$true
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -File "C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1" "`$$true"
C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -File "C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1" `$$true

以及多种这样的变体。

这是我的问题:当从windows快捷方式运行时,有没有办法将bool参数的值发送到脚本?

试试这个:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -command "& 'C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1'" -copyAll:$true

-file参数将bool传递给脚本的开关参数尝试:

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -file "C:Program FilesMySoftwarediagnosticDiagnosticTool.ps1" {-All:$False}

最后一个来自TechNet,但老实说,我永远无法使用它。

最新更新