Skip to content

Instantly share code, notes, and snippets.

@eterna1-0blivion
Last active September 27, 2025 08:12
Show Gist options
  • Select an option

  • Save eterna1-0blivion/70c1e5b14c7cfa8c6b6d574eb38fd27e to your computer and use it in GitHub Desktop.

Select an option

Save eterna1-0blivion/70c1e5b14c7cfa8c6b6d574eb38fd27e to your computer and use it in GitHub Desktop.
# author: eterna1_0blivion & soredake
# Get a link to the Registration Entries file
$link = "https://gist.github.com/eterna1-0blivion/70c1e5b14c7cfa8c6b6d574eb38fd27e/raw/context_pwsh_fix.reg"
# Install them into Registry using PowerShell
Invoke-WebRequest -Uri "$link" -OutFile "$env:TEMP/context_pwsh_fix.reg"
reg import "$env:TEMP/context_pwsh_fix.reg"
# Notify the user before exiting the program
Read-Host -Prompt "Press Enter to exit"
Exit
Windows Registry Editor Version 5.00
; author: eterna1_0blivion
[-HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\PowerShell7x64]
[-HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell]
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu]
"MUIVerb"="PowerShell"
"Icon"="C:\\Program Files\\PowerShell\\7\\pwsh.exe"
"SubCommands"=""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\0.PowerShell7.Run]
"MUIVerb"="Run with PowerShell 7"
"Icon"="C:\\Program Files\\PowerShell\\7\\pwsh.exe"
"CommandFlags"=dword:00000020
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\0.PowerShell7.Run\Command]
@="C:\\Program Files\\PowerShell\\7\\pwsh.exe -Command \"$host.UI.RawUI.WindowTitle = 'PowerShell 7 (x64)'; & {Set-ExecutionPolicy -Scope Process Bypass}; & \\\"%1\\\" \""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\1.PowerShell7.Run.Admin]
"MUIVerb"="Run with PowerShell 7 as Admin"
"Icon"="C:\\Program Files\\PowerShell\\7\\pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\1.PowerShell7.Run.Admin\Command]
@="C:\\Program Files\\PowerShell\\7\\pwsh.exe -WindowStyle Hidden -Command \"& {Start-Process pwsh.exe -ArgumentList \"\"\"-ExecutionPolicy Bypass -File \\\"\\\"%1\\\"\\\"\"\"\" -Verb RunAs} \""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\2.PowerShell5.Run]
"MUIVerb"="Run with PowerShell 5"
"Icon"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
"CommandFlags"=dword:00000020
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\2.PowerShell5.Run\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"& {Set-ExecutionPolicy -Scope Process Bypass}; & \\\"%1\\\" \""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\3.PowerShell5.Run.Admin]
"MUIVerb"="Run with PowerShell 5 as Admin"
"Icon"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\3.PowerShell5.Run.Admin\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -WindowStyle Hidden -Command \"& {Start-Process PowerShell.exe -ArgumentList \"\"\"-ExecutionPolicy Bypass -File \\\"\\\"%1\\\"\\\"\"\"\" -Verb RunAs} \""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\4.PowerShell.ISE]
"MUIVerb"="Edit with ISE"
"Icon"="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell_ise.exe"
"CommandFlags"=dword:00000020
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\CascadeMenu\Shell\4.PowerShell.ISE\Command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell_ise.exe \"%1\""
@tomasz1986
Copy link

Thanks a lot for the code! Just one comment - the current version will fail if the PS1 file contains the character ' in its name and you try to run it as administrator.

I have fixed this by changing

'-ExecutionPolicy Bypass -File \\\"%1\\\"'

into

\"\"\"-ExecutionPolicy Bypass -File \\\"\\\"%1\\\"\\\"\"\"\"

that only uses the double quote " character (which cannot appear in filenames in Windows).

@eterna1-0blivion
Copy link
Author

Thanks, @tomasz1986!

I didn't even think about this problem. Now it's fixed 🤝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment