Create Symbolic Link in Windows 10 with PowerShell

In Windows 10, you can using symbolic links to easily redirect one folder to another location. Symbolic links are widely used in the operating system for its own files and folders. Using symbolic links, you can save your disk space and make your data accessible from various file system locations without physically moving your data.

Symbolic links can be pretty useful in many situations. For example, some time ago I added an SSD drive to my computer and installed Windows there. All my portable apps remained in the D:\portable folder and many of them were configured to work with the folder D:\documents. The problem was that before I added this new SSD, the path to folders was C:\portable and C:\documents.

By symlinking these two folders I got everything working within a few seconds. I created symbolic links named c:\portable and c:\documents without moving a single file or folder. Another interesting thing is that if I move my symbolic links to some other location, for example, to the E: drive, they continue to work and will point to my folders on the D: drive.

In a previous article, we saw how to manage symbolic links with the built-in mklink console tool. Today, we will see how the same can be done using PowerShell.

To Create a Symbolic Link in Windows 10 with PowerShell,

  1. Open an elevated command prompt.
  2. Type or copy-paste the following command:
    New-Item -ItemType SymbolicLink -Path "Link" -Target "Target"
  3. Replace the Link portion with the path to the symbolic link you want to create (including the file name and its extension for files).
  4. Replace the Target portion with the path (relative or absolute) that the new link refers to.PowerShell Create Symbolic Link

You are done.
Besides that, you can use PowerShell to create directory junctions and hard links. Let's see how it can be done.

To Create a Directory Junction in Windows 10 with PowerShell,

  1. Open an elevated command prompt.
  2. Type or copy-paste the following command:
    New-Item -ItemType Junction -Path "Link" -Target "Target"
  3. Replace the Link portion with the path to the directory junction you want to create.
  4. Replace the Target portion with the full path to the directory that the new link refers to.PowerShell Create Directory Junction

To Create a Hard Link in Windows 10 with PowerShell,

  1. Open an elevated command prompt.
  2. Type or copy-paste the following command:
    New-Item -ItemType HardLink -Path "Link" -Target "Target"
  3. Replace the Link portion with the full path, including the file name and its extension for the hard link you want to create.
  4. Replace the Target portion with the full path to the file that the new link refers to.PowerShell Create Hard Link

Now you may wonder what is the difference between a directory symbolic link and a directory junction.

What is the difference between a directory symbolic link and a directory junction
A Directory Junction is an older type of symbolic link, which does not support UNC paths (network paths that begin with \\) and relative paths. Directory junctions are supported in Windows 2000 and later NT-based Windows systems. A directory symbolic link on the other hand also supports UNC and relative paths. However, they require at least Windows Vista. So, in most cases today, the directory symbolic link is the preferred option.

What is the difference between a hard link and a symbolic link
A hard link can be created only for files, not folders. You cannot create a hard link for directories. So, it has more limitations than a Directory Junction and also does not support UNC paths.

In Windows Vista and later, directory junctions are used to link older file folder paths like C:\Documents and Settings to newer paths like C:\Users. Symbolic links are also used to redirect C:\Users\All Users to C:\ProgramData.

Starting with Windows Vista, hard links are also widely utilized by Windows and its Servicing mechanism. Many system files are hard links to files inside the Windows Component Store folder. If you run the command fsutil hardlink list for explorer.exe, notepad.exe or regedit.exe, you can see this yourself!

Windows 10 system hard links The WinSxS folder stores various system files, which are linked via hard links to the files located in the folders C:\Windows, C:\Windows\System32 and other system folders. When operating system updates are installed, the files inside WinSxS are updated and hard linked to system locations again.

That's it.

1 thought on “Create Symbolic Link in Windows 10 with PowerShell

  1. Ronnie

    Hermann Schinagl has written Link Shell Extension which I use. It works well.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.