I am trying to launch a PowerShell script using keyboard shortcuts. My current script (super-simple, just prompts a yes/no popup) looks like this:
$a = new-object -comobject wscript.shell
$a.popup("Here's a test script", 0,"Title goes here", 4)
To make sure that it wasn't any lookup issues, I put both the script and the shortcut to the script on the desktop, namely:
- C:\users\me\desktop\ShortcutTest.ps1
- C:\users\me\desktop\ShortcutTest - shortcut.ps1
The Shortcut has the following settings in the properties:
Target: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File 'C:\Users\me\Desktop\ShortcutTest.ps1' Start in: C:\Users\me\Desktop Shortcut key: Ctrl + Alt + Q
the problem is when I press the shortcut it successfully starts a PowerShell window, but it immediately closes the instance.
Troubleshooting so far
- Running the shortcut as an administrator, same result
- Changing the location of the shortcut, same result
- Changing the location of the actual script, same result (it initially resided on a server that prevents scripts)
- Switching the 'Start in' and 'Target' sections of the shortcut, same result
- Removing the -File parameter from the 'Target' in the shortcut makes the PowerShell instance remain opened, so I'm guessing that I'm missing some form of parameter settings in the script, or when calling it from the shortcut.
- Changing the script contents to a simple 'Write-Host "Great success"' still closes the PowerShell instance immediately, further making me suspect that it is the parameters used in the 'Target' (-File and -ExecutionPolicy) that is missing something.
If anyone has any tips on how I could solve this, or at least troubleshoot further, it would be greatly appreciated!