Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch powershell script with keyboard hotkey

I want to execute a powershell script (ps1-file) with a hotkey on my keyboard (CTRL + SHIFT + F for instance).

I managed to create a shortcut of the script (right click in explorer > new > shortcut). The shortcut's target is: "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "PATH_TO_THE_SCRIPT" ".

When I execute the script manually (by double-clicking the shortcut), it works like a charm. But when I try to assign a "Shortcut key" in the Shortcut Properties (CTRL + SHIFT + F) and press the shortcut key I just defined, nothing happens. What's the matter?

I'm quite sure it has something to do with security policies. But I don't know what exactly it is.

This is my Execution-Policy:

Scope ExecutionPolicy
----- ---------------
MachinePolicy  Undefined
UserPolicy     Undefined
Process        RemoteSigned
CurrentUser    Unrestricted
LocalMachine   Unrestricted

Any help is appreciated.

like image 479
theRunner Avatar asked Sep 24 '16 14:09

theRunner


People also ask

How do I start PowerShell from the keyboard?

One of the quickest ways to start PowerShell in any modern version of Windows is to use the Run window. A fast way to launch this window is to press the Win + R keys on your keyboard. Then, type powershell and press the Enter key or click OK.

Which keyboard shortcut opens the Run program?

The fastest way to access most Windows software programs is through keyboard shortcuts. To quickly access the Run command dialog box, simply press the Windows key + R.

What keyboard shortcut will allow you to launch a script directly from the PowerShell ISE?

A great feature of the PowerShell ISE is that you can select one or more sections of code, press F8 and the highlighted section will run. You can also run a single line of code this way. You don't even need to select it all. If you press F8, then the ISE will run the line of code that contains your cursor.

How do I launch a PowerShell script?

In File Explorer (or Windows Explorer), right-click the script file name and then select "Run with PowerShell". The "Run with PowerShell" feature starts a PowerShell session that has an execution policy of Bypass, runs the script, and closes the session.


1 Answers

That's it. As soon as I move the shortcut file to the desktop and redefine the "shortcut key", the shortcut key works!

Is there a particular reason, why the shortcut has to be on the desktop?

like image 94
theRunner Avatar answered Sep 21 '22 00:09

theRunner