1

So I have successfully bound a key to open this script:

shortcut settings

But the way to run that script with PowerShell is to right-click it and go Open with PowerShell. Using the key binding, it just opens it normally (so with notepad).

How can I make it so it opens with PowerShell from that binding?

stackprotector
  • 10,498
  • 4
  • 35
  • 64
Thomas Adnum
  • 21
  • 1
  • 5

3 Answers3

4

You already have a lnk that points to your script file. Make that point to PowerShell and pass your file as a parameter. Assuming your file is located in C:\PSScripts you would have to set the Target of the lnk to

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& C:\PSScripts\Display Off.ps1" -NoLogo -NonInteractive -NoProfile

enter image description here

1

Go to the General tab in your shortcut settings, and change the Open with row from notepad to

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
stackprotector
  • 10,498
  • 4
  • 35
  • 64
0

So, you can't run PS script, because security feature. User can't double click it. You can create simple .bat like:

powershell -command Set-ExecutionPolicy RemoteSigned 
powershell -command Your Script
powershell -command Set-ExecutionPolicy Restricted

Check too this topic: Is there a way to make a PowerShell script work by double clicking a .ps1 file? There are more solutions there.

Przetczak
  • 119
  • 1
  • 11