What is equivalent of mklink in Windows Powershell?
Asked Answered
B

2

17

When I shift-right-click on a folder I had been able to "open command window here".

NOTE: I am NOT INTERESTED in the registry hack to put this feature back on.

After which I could use mklink to create symbolic links.

Under recent profound wisdom of Microsoft, after last couple of Windows 10 updates, "command window here" has been replaced with "powershell here".

Hence complying with Microsoft's esteemed wisdom implying that I should use powershell instead of the long outdated cmd

  • what is the equivalent of making a softlink in powershell?
  • and any other type of link that mklink could make?
Baalman answered 23/5, 2018 at 0:17 Comment(6)
I think this is off-topic for this site, but you can go into the address bar for a folder and type cmd to get a command shell there. From PowerShell you can do cmd /c mklink. There is no command currently included in PowerShell that does this, to my knowledge.Eri
Possible duplicate of Creating hard and soft links using PowerShellGranddad
Win10/PS5 supports this with New-ItemGranddad
new-item can create HardLink, SymbolicLink, and Junction link types. However, unlike CMD's mklink, it can't create a SymbolicLink or Junction to a non-existent target. It used to support creating a plain symbolic link (i.e. not a directory symbolic link) to a non-existent target, but that's not working in the latest release of Windows 10. Maybe it was causing too much confusion with people expecting Windows symbolic links to function like Unix symlinks.Offertory
Also, remove-item can't remove a directory symbolic link in PowerShell 5.1. You have to use the more verbose command [IO.Directory]::Delete('symlink_path'). remove-item works to delete a junction, but it requires -force and displays a warning as if it's going to delete the contents of the target directory, when it actually doesn't (at least not in 5.1). I'm surprised they released code in such an unfinished state.Offertory
superuser.com/questions/98420/mklink-not-installed-on-windows-7Volta
M
19

This is answered in [1]: https://mcmap.net/q/98168/-creating-hard-and-soft-links-using-powershell

But use New-Item Powershell command. No DOS CMD necessary any more.

   New-Item -Path <to> -ItemType SymbolicLink -Value <from>

where <to> is the location to put the new symlink, and <from> is the target of the new symlink. E.g.

   New-Item -Path "$env:USERPROFILE\desktop\MyNewLinkToCmd.exe" `
            -ItemType SymbolicLink -Value "c:\windows\system32\cmd.exe"

Also note that you must run this from Powershell running as administrator.

Melpomene answered 2/12, 2020 at 18:31 Comment(2)
For a relative directory symlink, make sure to prefix the from path with .\ or you will end up with a broken file symlink. Others also pointed out that you may need a somewhat new PowerShell version (at least pwsh 7.1.x) for this to work.Dira
Due to a still-not-fixed bug from 2018, it is actually necessary to use mklink in some cases; see github.com/PowerShell/PowerShell/issues/6232Jakoba
E
14

You can create soft links in PowerShell via:

cmd /c mklink /J "<link>" "<target>"

The above uses old cmd in PowerShell. However, the above does not work for symbolic links (/D).

Elwell answered 8/9, 2020 at 19:0 Comment(1)
Just wanted to point out the quotes in this can cause problems when copying and pasting. Use " instead of “ or ”.Amphibiotic

© 2022 - 2024 — McMap. All rights reserved.