Passing bool parameter to powershell script shortcut

I wrote a powershell script file that takes a bool parameter. I also have a windows shortcut for this powershell script. The problem is that whenever I try to run a script from a shortcut, the parameter is interpreted as a string, not a bool, but the script crashes.

This is what I originally posted in the target section of my shortcut:

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

I searched for solutions on the Internet and also tried the following options:

 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 

And a few of these variations.

This is my question for you: is there a way to send the value of the bool parameter to a script when running a from a Windows shortcut?

+4
source share
1 answer

try the following:

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

with the -file parameter pass bool to the switch parameter of your script try:

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

The last one is made from TechNet , but to be honest, I can never work with it.

+4
source

Source: https://habr.com/ru/post/1490470/


All Articles