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
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,
- Open an elevated PowerShell.
- Type or copy-paste the following command:
New-Item -ItemType SymbolicLink -Path "Link" -Target "Target"
- Replace the Link portion with the path to the symbolic link you want to create (including the file name and its extension for files).
- Replace the Target portion with the path (relative or absolute) that the new link refers to.
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,
- Open an elevated PowerShell.
- Type or copy-paste the following command:
New-Item -ItemType Junction -Path "Link" -Target "Target"
- Replace the Link portion with the path to the directory junction you want to create.
- Replace the Target portion with the full path to the directory that the new link refers to.
To Create a Hard Link in Windows 10 with PowerShell,
- Open an elevated PowerShell.
- Type or copy-paste the following command:
New-Item -ItemType HardLink -Path "Link" -Target "Target"
- Replace the Link portion with the full path, including the file name and its extension for the hard link you want to create.
- Replace the Target portion with the full path to the file that the new link refers to.
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!
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.
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
Hermann Schinagl has written Link Shell Extension which I use. It works well.
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.
You can’t run PS cmds in a CMD window. Please fix all the links to “elevated command prompt”. Otherwise, a very helpful article.
Thanks! Updated the article.
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.
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!
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.
thanks for your valuable additions.