67

If there's docs on it, I'll take that. Any web searches for "symlink" "symbolic link" "windows [10]" "powershell" returns everything except the base command.

Even the powershell docs site returns nothing. Is this not possible?

4
  • 1
    Why don’t you want to use mklink you can call it from a PowerShell prompt and/or script
    – Ramhound
    Commented Mar 24, 2018 at 0:51
  • 2
    Please see docs.microsoft.com/en-us/powershell/wmf/5.0/feedback_symbolic
    – Epoxy
    Commented Mar 24, 2018 at 1:07
  • 3
    @Epoxy Thank you. Fun Fact: using the search box on the top level of that site returns "No results" when searching for sym. In other words, you can't find it if you don't know where it is.
    – monsto
    Commented Mar 24, 2018 at 1:15
  • You are quite welcome! :)
    – Epoxy
    Commented Mar 24, 2018 at 1:19

2 Answers 2

65
  1. Start powershell as admin
  2. You need to know 1) the path to target of the link 2) path to location where you want the link 3) the name you want to use to refer to the link.
  3. PS C:\> new-item -itemtype symboliclink -path <path to location> -name <the name> -value <path to target>

Example: If you're in c:\drivers\AMD and you want to link in f:\driver\olddrivers, then you would go

PS C:\> new-item -itemtype symboliclink -path . -name OldDrivers -value f:\driver\olddrivers

And wind up with a symlink path of c:\driver\AMD\OldDrivers

4
  • 1
    That's because mklink is a specific tool for a specific purpose. Powershell New-Item is a very general tool. It can do much more than create directories and symlinks.
    – monsto
    Commented Mar 24, 2018 at 3:07
  • 3
    perfect! for those who are wondering, this also works for creating symbolic links to directories ... PS C:\Users\mcoog> New-Item -itemtype symboliclink -path . -name .vim -value C:\Users\mcoog\Dropbox\.vim
    – ricardo
    Commented Aug 11, 2018 at 5:05
  • 3
    FYI, ItemType SymbolicLink was added in PowerShell 5.0
    – Brettski
    Commented Nov 9, 2018 at 5:29
  • 1
    @monsto you could argue that tools should be very specific rathen than broad in usage
    – Dragas
    Commented Feb 3, 2020 at 8:24
60

Use the New-Item cmdlet and specify the appropriate ItemType of SymbolicLink, HardLink, or Junction. Note that these are only available from PowerShell 5.1 or newer.

+-----------------------+-----------------------------------------------------------+
| mklink syntax         | PowerShell equivalent                                     |
+-----------------------+-----------------------------------------------------------+
| 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     |
+-----------------------+-----------------------------------------------------------+
3
  • 3
    This should be the answer Commented Nov 12, 2020 at 18:44
  • 1
    note: in my tests, -Name takes a file name, not a file path, replace by -Path to give a file path Commented Jul 28, 2022 at 17:26
  • Very useful. Thanks.
    – MC Emperor
    Commented Aug 25, 2022 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .