If wanting to run a .ps1 with a double click it IS possible to edit the registry to allow this, the issue is that scripts that aren't elevated may fail, and it bypasses some of the ExecutionPolicy
restrictions or hardcodes the same policy for all of them.
This Q&A has a number of options for making it work, but the best practice scenario I'm going with is creating a .bat file to call a .ps1 file, and then putting a shortcut to the .bat file on the Public Desktop so that the shortcut can be set to run as Administrator and prompt for the password if UAC is configured that way.
For reference the "Run with PowerShell" in the right click menu uses this as the "Command" registry key, "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
If a user has changed the association via the GUI there is an override in their registry path. You can simply delete this to use the system-wide setting.
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\UserChoice
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1\OpenWithList
Making a choice to use another program also creates an OpenWithList
folder/key that can be deleted to reset the Open With to just the default program as well.
There is an empty entry in HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.ps1
Other keys pertaining to Microsoft.PowerShellScript.1
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Microsoft.PowerShellScript.1
HKEY_USERS\S-1-5-21-2600432384-240279299-2107569243-3351\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1
HKEY_USERS\S-1-5-21-2600432384-240279299-2107569243-3351\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1
HKEY_CLASSES_ROOT\.ps1
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ps1