Creating a Symlink on Windows 11

4.9/5 - (8 votes)

So, I finally got a new device and have been getting it set up the way I use it.

I still do a lot of scripting between authoring, customer assistance, and tooling for the general public.  While I do store all of my scripts in OneDrive, having to navigate to \Users\<username>\OneDrive - Microsoft\Scripts is a pain when you need to do it frequently.

To have the best of both worlds (ease of navigation, but also including my scripts folder in a default OneDrive path), I use a symbolic link (often abbreviated as symlink).  Junction points were introduced to NTFS in Windows 2000 (junctions and symlinks are very similar, and sometimes the verbiage is used interchangeably).  The tooling to do this has been around forever:

My goal is a create a local path (C:\Scripts) that is linked to my OneDrive for Business scripts directory.  Here we go!

  1. Launch an elevated Command Prompt.
  2. Run mklink /D <link target> <link source>.  In my case, it was mklink /D C:\Scripts "C:\Users\aaguilme\OneDrive - Microsoft\Scripts"

That’s it! The /D indicates that we’re working with a directory (without it, mklink.exe assumes you’re working with a file object and will generate an error).

So now, I can type cd \Scripts from a fresh command prompt and get directly to my intended path.  If you go to the root of the directory, you can see the type of object displayed:

Yay for links! It can make your CLI navigation experience so much easier!