It seems that the only time Windows shows "Run with PowerShell" in the content menu of a ps1 file is when the default application is Notepad. If I change the default application to the PowerShell ISE (or any other editor, for that matter), the "Run with PowerShell" context item doesn't appear.
Windows 7 Professional SP1, WMF 4.0
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.
Windows sets the default action for . PS1 files to open them in Notepad, instead of sending them to the PowerShell command interpreter. This is to directly prevent accidental execution of malicious scripts when they're simply double-clicked.
The default execution policy, Restricted , prevents all scripts from running, including scripts that you write on the local computer. For more information, see about_Execution_Policies. The execution policy is saved in the registry, so you need to change it only once on each computer.
While running PowerShell script, if you get running scripts is disabled on this system, it is because the PowerShell execution policy is set up by default as Restricted and doesn't allow to run script. PowerShell has built-in security features implemented.
In Windows 10 press Start then type "default app settings", click on "Default app settings". A new windows comes up "Choose default apps by file type". Scroll to ".ps1". Click on the current app icon, then select Notepad.
As elmonty stated, this will restore the "Run with PowerShell" context menu entry when right clicking on a ps1 file.
You can copy the below into a text file and import into your registry. This will open the PowerShell console and execute the script when you double click on a ps1 file.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
@="\"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" \"-Command\" \"if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'\""
or open regedit, navigate to:
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
doulbe click on the (Default) string entry and enter the following in the "Value data:":
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
I found out the answer. You must set the default application back to Notepad. This will restore the "Run with PowerShell" context item. Next, you have to edit the "Open with" application directly in the registry, here:
\HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command
Change the value to:
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe" "%1"
Or you can change it to the editor of your choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With