5

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?

3 Answers 3

9

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.