Advertisement

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.

Advertisеment

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 PowerShell.
  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 PowerShell.
  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 PowerShell.
  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 linksThe 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.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

9 thoughts on “Create Symbolic Link in Windows 10 with PowerShell”

  1. From what I can tell, new-item converts relative paths to absolute paths for the target. This can be a deal breaker when used with a source control system like git and many colaborators with diff folder structures. It was for me at least, I had to resort to calling mklink command with-in my powershell cmdlet that created the symbolic link. I just thought you should know.

  2. You can’t run PS cmds in a CMD window. Please fix all the links to “elevated command prompt”. Otherwise, a very helpful article.

    1. FYI for anyone finding this in the future – it is possible to run PS commands in a CMD window. From a command prompt, running the command “powershell” will open an instance of PowerShell for further commands (or “pwsh” depending on your version of powershell). Similarly, from an instance of PowerShell you can open an instance of command prompt with the command “cmd”. In either case, you can go back to where you started with the command “exit”. Note that you can go many layers deep with this, running CMD inside Powershell inside CMD inside CMD inside Powershell.

  3. This way of linking something too long, but to be honest, this wrapper for mklink is quite great, the concept is good, but I just think it should be allowed even it’s not super user/ admin.

    Anyway this’s a good article, I struggling to find this on cmd/powershell docs for a while, and this save my day! Thanks!

  4. Thanks for the article! One small remark: Only the SymbolicLink type requires a PowerShell session elevated as administrator. The other types don’t need that (Junction, HardLink or the ordinary File or Directory ones).
    Furthermore, on Windows 10 build 14972 or newer (that is since the Creators Update version — spring 2017) creating symbolic links no longer requires elevation if the Developer Mode is enabled.

  5. Pingback: Réponse du code "Windows PowerShell Symlink" - Coder les réponses

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.