Add File Templates to the 'New' Menu in the Context Menu


Windows Forum Team
Staff member
In this tutorial I will be showing how to add new file types to the 'New' submenu on the context menu. The context menu, if you're not familiar with it, is the menu that shows up when you right click on an empty area on the desktop or within the file explorer.

Context Menu

To add a new file type to the 'New' submenu we need to add a couple of items to the registry. There are several locations in the registry that this can be achieved. The reason for this is that it allows the system to be configured for say a general default configuration, but also allows users to have their own unique customizations. For the sake of simplicity I'll stick to the system configuration.

First go ahead and open regedit which can be done by pressing the following key combo [windows key + r] and typing regedit.
I'l be adding a Windows PowerShell Script file type (.ps1) to the menu, but the process is the same for any file type.

Once in regedit expand the HKEY_CLASSES_ROOT registry hive and scroll down to the PowerShell script shell extension (.ps1)

Right click on .ps1 folder and select New > Key. Name it ShellNew
Now expand the .ps1 key and select ShellNew
Right click in the right hand pane and select New > String value. Name it NullFile
One quirk, is you will need to right click and expand the New menu before explorer will detect the new item

That's all it takes to add a file type to the 'New' submenu

That's pretty useful. We can now quickly create those file types, but we can make it more useful with templates.

When I create a new Windows PowerShell Script and open it we can see it's just an empty file.

We can extend the the New file by pre-populating it with data in two ways.
The first is if we just want to append a single line of data. Back in regedit (hopefully you didn't close it). If you did open it back up and navigate to HKEY_CLASSES_ROOT\.ps1\ShellNew

In the right hand pane right click and select New > String value. Name it Data
Double click on the Name (Data) and add any text you want to appear in the new file.
Now when you create a new Windows PowerShell Script you should see that text in the file.

And the new file...

Well that seems a bit more helpful but what if you want a lot more data pre-populated? That is where the template file comes into play.

Now in regedit lets right click in the right hand pane and add another string value New > String value. Name it FileName.
It's ok to leave the Data value as Windows will ignore it if it sees the FileName value.
Double click the FileName value and enter the name of your template file, I just called mine MyPowerShellScriptTemplate.ps1
Now create a file with the same name and add any data you want new files to have. I've just added some title info and a function template.

Windows will look in three locations for this template file in the following order. This again allows for system level templates and customized ones for individual users.

Template Search Locations



I've added my template the bottom location since I'm doing a system wide configuration (You may need to create the ShellNew directory if it does not exist)

Now when we create a new Windows PowerShellScript file and open it we should see the content of our template file.