Add Network Location/Drive using Powershell + Context Menu

I’ve received a request from one of my customers were they wanted a button or an application that could bypass the 255 max char file path length. Some inexperienced users often like the file tree structure so much that they name their folders with a complete essay which will override the max char file path length in a few seconds.

One way to overcome the file path length is to use mapped network drives, i.e. \\\dfs\human_resources will be L:\. This method replaces any UNC network path with three letters instead of 33 in the example above.

Now you may start to wonder if this blog post is necessary. Use Group Policy Preference (Drive Maps) to map the UNC network path and manage every thing from a central location. Well of course this works when you have a few network shares and the users build their file tree structure on the width instead on the depth.
With our larger customers we try to use “Network Locations” using “GPP Shortcuts” instead of Drive Maps, the reasons are:

  1. Drive Maps only have a limited number of letters to use. 22 letters available (A,B, C and D excluded).
  2. Some Servicedesk conversations can beĀ misinterpreted if you use the same drive letter for two or more locations.
  3. Application/system owners may use a drive letter for file based application search paths.
    Trust med this is an issue with slow WAN-links and when you want change or do some restructure in the file servers.
  4. Network Locations uses shortcuts to point to a UNC path. When accessed the shortcut translates to the full UNC path.

And of course with Network Locations there are some side effect and that are the max file path length issue when you have some users you like to write. So the reason that i started to write this script is for the end user to use when he or she encounters large file path lengths.

Here is the script:


An issue with this script is that the end users doesn’t use Powershell so I’ve had to come up with a way every user in the organization can bypass the long path file name with their favorite tool (the computer mouse). The first thing I did was to compile the script to executable file using Powershell Studio 2016. Now that I have the .exe file I need some way for the users to run the file using their mouse.

Context menu was the clear way to go.
Context Menu

The following registry settings are applied to accomplish the picture above:

One problem with the registry settings above is that C: is the SystemDrive disk.
This settings only apply to folders when you right click on them, according to the picture. You will not be able to right click in a folder to map to a network drive / location.

To insert the registry settings and the .exe application on the users computer I’ve created a .msi installer again using Powershell Studio 2016 so we can deploy everything either with GPO or ConfigMgr. I you are interested in the .exe or the .msi just write back to me or create your own using the source code above.

I hope this will help someone with network location or drive maps when using Powershell and a start with context menu while right clicking folders.