Make right-click “Run with PowerShell” use PowerShell 7 (one command)
Windows still sends “Run with PowerShell” to the old 5.1. Switch it to PowerShell 7 with one no-admin command, or a custom ProgID — plus how it works and how to undo it.
Right-click a
.ps1file in Explorer, pick Run with PowerShell, and Windows still launches the legacy Windows PowerShell 5.1. If you’ve installed PowerShell 7, there’s no reason it shouldn’t handle your scripts. Below are two clean ways to switch (the first is the one most people need), along with how it works, how to roll back, and what to watch out for.
How it works (the 30-second version)
What happens when you run a script from the context menu is decided by three chained registry entries:
.ps1 file association → ProgID (programmatic identifier) → Shell\<verb>\Command (the command that actually runs)
- Out of the box:
.ps1points toMicrosoft.PowerShellScript.1. To stop scripts from running on an accidental double-click, its defaultOpenverb opens the file in Notepad, while theRunverb launches the oldpowershell.exe(5.1). - After installing PowerShell 7 (MSI): you usually get a ready-made ProgID such as
Microsoft.PowerShellScript.7orPowerShell7.scriptthat points topwsh.exe.
So the whole fix boils down to one idea: redirect the .ps1 ProgID for the current user, or override its Run / Open verb commands.
Option 1 (recommended): switch the file association — no admin needed
If you installed PowerShell 7 from the MSI and its ProgID is registered, run this in any PowerShell window (no elevation required):
reg add "HKCU\Software\Classes\.ps1" /ve /d "Microsoft.PowerShellScript.7" /f
Or the PowerShell-native equivalent:
Set-ItemProperty -Path "HKCU:\Software\Classes\.ps1" -Name "(default)" -Value "Microsoft.PowerShellScript.7"
Why this is the best option
- No elevation: it writes only to
HKCU(your user profile) and never touches the machine-wideHKLMhive. - Non-destructive: none of the system’s ProgIDs are modified. You’re adding a per-user override, so deleting that one key restores the defaults instantly.
- Instant: it takes effect right away — no need to restart Explorer or reboot.
💡 Check the prerequisite first
This option needs Microsoft.PowerShellScript.7 and its command to exist. Check with:
Test-Path "Registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.7\Shell\*\Command"
True means you’re good to go with Option 1. False (common with the Microsoft Store build, the portable ZIP, or an MSI installed without file associations) means you should use Option 2.
Option 2 (advanced): register your own ProgID and control the command line
Registering your own ProgID under your user profile works with every PowerShell 7 build (MSI, Store or portable ZIP), and lets you tweak the launch arguments — hide the banner, bypass the execution policy, and so on.
Step 1: find the real path to pwsh.exe
(Get-Command pwsh).Source
# Typical MSI output: C:\Program Files\PowerShell\7\pwsh.exe
Step 2: register the ProgID and wire up the context menu
Set $pwsh to your actual path, then paste the script into any PowerShell window:
$pwsh = "C:\Program Files\PowerShell\7\pwsh.exe"
# 1. Register the "Run with PowerShell 7" context-menu entry (Run verb)
New-Item -Path "HKCU:\Software\Classes\MyPsScript7\Shell\Run\Command" -Force | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Classes\MyPsScript7\Shell\Run" -Name "(default)" -Value "Run with PowerShell 7"
Set-ItemProperty -Path "HKCU:\Software\Classes\MyPsScript7\Shell\Run\Command" `
-Name "(default)" -Value "`"$pwsh`" -NoLogo -File `"%1`" %*"
# 2. Double-click action (Open verb): run these two lines only if you want double-click to execute scripts
New-Item -Path "HKCU:\Software\Classes\MyPsScript7\Shell\Open\Command" -Force | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Classes\MyPsScript7\Shell\Open\Command" `
-Name "(default)" -Value "`"$pwsh`" -NoLogo -File `"%1`" %*"
# 3. Associate .ps1 with the new ProgID
reg add "HKCU\Software\Classes\.ps1" /ve /d "MyPsScript7" /f
⚡ A handy variant
If your local scripts keep getting blocked by the execution policy, or the window closes before you can read the error, use this command instead (it adds -ExecutionPolicy Bypass and -NoExit):
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoExit -ExecutionPolicy Bypass -File "%1" %*
⚠️ Security note:
-ExecutionPolicy Bypassignores script-signing and execution restrictions. Use it only on your own dev machine, and never run.ps1files from sources you don’t trust.
Check that it worked
- Create a test script containing
$PSVersionTable.PSVersion; Pause, right-click it and run it. - Look at the window title or the printed version. If
Majoris7, you’re done.
Roll back in one step
To go back to the Windows default (PowerShell 5.1), delete the per-user overrides and the system defaults take over again immediately:
# Restore the default .ps1 association
Remove-Item -Path "HKCU:\Software\Classes\.ps1" -Recurse -Force
# (Optional) If you used Option 2, remove the custom ProgID too
Remove-Item -Path "HKCU:\Software\Classes\MyPsScript7" -Recurse -Force -ErrorAction SilentlyContinue
Gotchas
- Avoid the Store (MSIX) app execution alias. The Store build’s default path,
C:\Users\<username>\AppData\Local\Microsoft\WindowsApps\pwsh.exe, is a virtual reparse point and can fail in some context-menu scenarios. Prefer the official MSI and hard-code the stable pathC:\Program Files\PowerShell\7\pwsh.exe. - Watch out for accidental double-clicks. Windows opens
.ps1files in Notepad on double-click precisely so you don’t run a dangerous script by mistake. If you point theOpenverb atpwsh.exein Option 2, double-clicking a.ps1runs it straight away. Convenient — just be aware of it. - The GUI route has limits. Using Open with on a
.ps1file, choosingpwsh.exeand ticking Always spares you the command line, but it locks theOpen(double-click) action through theUserChoicehash. You can’t customize arguments like-File, and it sometimes makes the context-menu entry disappear or throw errors. The registry approach gives you far more control. - Windows 11 hides the entry. The new Windows 11 context menu tucks classic shell entries into a submenu. If you don’t see the option, click Show more options at the bottom (or hold
Shiftwhile right-clicking).
Originally published in Chinese on Zhihu by the author, 滴滴点到 (Liang Cui), and adapted for AI SI Daily.
Related
Microsoft PowerToys: What It Is and How to Get Started
Learn how Microsoft PowerToys helps customize Windows, streamline daily tasks, and boost productivity with over 30 helpful desktop utilities.
Rectangle for Mac: Overview, Capabilities, and Setup Guide
An introductory guide to Rectangle, an open-source macOS window management application featuring keyboard shortcuts, snap areas, and grid tiling.
LocalSend Guide: Cross-Platform Local File Sharing
Learn about LocalSend, an open-source tool for sharing files and messages across platforms over your local network without internet servers.