Search This Blog

Thursday, May 1, 2025

PowerShell: New .ps1 in context menu

The context menu is the menu that shows up when you right-click in your explorer window. This is where you can create new files, folders and shortcuts.

So as I am a bit of a PowerShell nerd I thought it would be handy to have the .ps1 file in the context menu where you create new files as well. I found a reliable source at Winaero and a reg file created by Sergey Tkachenko (press the click here to download) to get the zip folder.

Compiling the research this is essentially the steps you need to take:

1. Open regedit as administrator and go to HKEY_CLASSES_ROOT and find the key for .ps1 files.

2. Change the value of "(Default)" to ps1legacy. Mine was set to ps1_file_auto


3. Create a new key (folder) under the .ps1 extension in the left pane. Name it ShellNew and within it create a new string value called NullFile and make sure the data is empty.


4. On the top level of HKEY_CLASSES_ROOT, create a new key for it named ps1legacy, give the "(Default)" the data Windows PowerShell Script. Create a new string value in the same place with the name FriendlyTypeName, give it the same data as the other string value.




Here is the result! 😊



Lastly, let's explore how we with some lines of PowerShell code could create the same result. This code snippet is boiled down to the essentials on purpose for simple step-through, reviewing and modification.

# Run as admin #

Set-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\.ps1" -Name "(Default)" -Value "ps1legacy"

New-Item -Path "Registry::HKEY_CLASSES_ROOT\.ps1\ShellNew" -Force

Set-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\.ps1\ShellNew" -Name "NullFile" -Value ""

New-Item -Path "Registry::HKEY_CLASSES_ROOT\ps1legacy" -Force

Set-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\ps1legacy" -Name "(Default)" -Value "Windows PowerShell Script"

Set-ItemProperty -Path "Registry::HKEY_CLASSES_ROOT\ps1legacy" -Name "FriendlyTypeName" -Value "Windows PowerShell Script"



No comments:

Post a Comment