>>FIRST MISSION//LOGS//command prompt//powershell-symbolic-links-in-windows-10.MD
[ + ] TARGET_LOCKED200 OK
JAN 06, 2021timer 3 MIN READSYS_TAG: command prompt STATUS: VERIFIED_WORKING

Powershell Symbolic Links in Windows 10

ENGINE: KERNEL // STABLE
BASE_ARCH: x86_64
HOST: VASTORIGINS.COM
GPG: OKSIG_ID: 0x4EB27DB0
Powershell Symbolic Links in Windows 10
SPEC_IMAGE // PROVENANCE_VERIFIED

Recently, I’ve been using the Powershell1 prompt more than the old command prompt2. Both command consoles can still run on Windows 10, but on recent occasions I prefer Powershell, as you can use it to create more complex shell scripts on Windows and access some C# modules. Once you get used to piping objects instead of text, going back to cmd.exe feels like driving a car with square wheels.

The one thing that kept pulling me back to the old prompt, though, was mklink. Every time I needed a symbolic link, I instinctively reached for the command I had been using for years, forgetting that Powershell has its own, much cleaner way to do it.


A chain is only as strong as its weakest link.

~ Anonymous.

On my previous recent post about moving ProgramData to another drive, I used the mklink utility to create junction directories to-and-from. So here are the equivalent commands:

πŸ”— The Command Comparison

Command Prompt Syntax Powershell Equivalent Syntax
mklink Link Target New-Item -ItemType SymbolicLink -Name Link -Target Target
mklink /D Link Target New-Item -ItemType SymbolicLink -Name Link -Target Target
mklink /H Link Target New-Item -ItemType HardLink -Name Link -Target Target
mklink /J Link Target New-Item -ItemType Junction -Name Link -Target Target

The table shows the whole mapping at a glance. Notice that both mklink (file symlink) and mklink /D (directory symlink) map to the same Powershell command, because Powershell figures out the type from the target automatically. The hard link and junction variants map to their own -ItemType values, so the full set of link types is preserved.

πŸ“ Notes and Gotchas

The New-Item command is also analogous to the Unix touch command tool, which makes it a versatile friend: it can create files, folders, and links, all through the same interface.

One important difference between the two worlds: in cmd.exe, mklink is a built in command that always exists. In Powershell, New-Item needs the right permissions to create symbolic links, and on Windows 10 you may need to run your terminal as Administrator, or enable Developer Mode in the settings, or the operation fails with an access denied error. Junctions, thankfully, do not require those privileges, which is why they are the go to for folder redirection scripts.

Check the definition of the commands before running them on your system.

That’s all guys!

🧠 Final Thoughts

Learning the Powershell equivalent of your old command prompt habits is how the switch becomes permanent. The table above is the only translation you need for links: symbolic, hard, or junction, and once the syntax clicks, you will stop opening cmd.exe for mklink and start scripting the whole thing.

Leave a comment if you have questions or queries. Also, you can DM me on twitter πŸ˜‰.

πŸ’»


  1. PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it was made open-source and cross-platform on 18 August 2016 with the introduction of PowerShell Core. β†©οΈŽ
  2. The name refers to its executable filename. It is also commonly referred to as cmd or the Command Prompt, referring to the default window title on Windows. The implementations differ on the various systems, but the behavior and basic set of commands is generally consistent. cmd.exe is the counterpart of COMMAND.COM in DOS and Windows 9x systems, and analogous to the Unix shells used on Unix-like systems. β†©οΈŽ
[ SIGNATURE VERIFIED // GPG 0x4EB27DB0 // PROVENANCE SECURE ]
βž” RETURN TO LOGS