2

VS Code is trying to position itself as a new way to work with Powershell, and one of the changes it makes upon installation is to replace the File Explorer context menu option "Run with PowerShell" on .ps1 files with a new "Open with Code" option instead.

Is there a way to remove the "Open with Code" option and replace it with the old "Run with PowerShell" option? I assume this would involve the registry somehow but I don't know enough about the registry in general to do it safely.

2 Answers 2

2

Try this:

Save the following contents into a file "EnablePowerShellRightClickRun.reg", then right click - merge.

Then it doesn't matter which application you associate .ps1 files with - you still have "Run with Powershell" as a right click option.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunPS]
@="Run with Powershell"

[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\shell\RunPS\command]
@="\"C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe\" -File \"%1\""
Sign up to request clarification or add additional context in comments.

Comments

1

VS Code is not really positioning itself as the new way to work with PowerShell, it will be the only "built-in" way with Windows to work with it because the PowerShell ISE is being depreciated.

Either way, VS Code did not cause that option to disappear. I have VS Code and the PS extension on my machine and still have access to both options:

enter image description here

When you install VS Code you are prompted to add the right-click menu options, so if you opt'ed into those then it is not what removed your "Run with PowerShell" option.

enter image description here

If you want to remove those right-click options then you would have to uninstall VS Code and install it again, making sure those options are not checked.

To restore your menu option to Run with PowerShell verify you have not changed the default program for PowerShell files (e.g. ps1). If you set that to VS Code it will cause the option to be removed from your right-click menu. You can restore it by changing the default program in Windows back to Notepad.

enter image description here

2 Comments

This gets most of the way there, however it seems that the "Run with powershell" option is not restored after reinstalling Code with those options unchecked. Powershell is still the default program but the context menu option is still absent. However, double-clicking the files will execute them now, rather than opening them for edit, so while there's no real show stopper it's still a bit of an administrative headache. Thanks though, this is good information.
Also, for other readers, here's a link on deprecation of Powershell ISE. 4sysops.com/archives/… This is quite disappointing because at present the VS Code experience for powershell is pretty terrible.

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.