What is equivalent of mklink in Windows Powershell?
Solution 1
This is answered in [1]: https://stackoverflow.com/a/34905638/4744055
But use New-Item
Powershell command. No DOS CMD necessary any more.
New-Item -Path <to> -ItemType SymbolicLink -Value <from>
Solution 2
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).
Related videos on Youtube
Comments
-
Blessed Geek almost 2 years
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?
-
Kory Gill almost 6 yearsPossible duplicate of Creating hard and soft links using PowerShell
-
Kory Gill almost 6 yearsWin10/PS5 supports this with New-Item
-
Eryk Sun almost 6 years
new-item
can create HardLink, SymbolicLink, and Junction link types. However, unlike CMD'smklink
, 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. -
Eryk Sun almost 6 yearsAlso,
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.
-
Adam Dylla about 3 yearsJust wanted to point out the quotes in this can cause problems when copying and pasting. Use " instead of “ or ”.