Microsoft uses "soft link" as another name for "junction".
However: a "symbolic link" is something else entirely.
See MSDN: Hard Links and Junctions in Windows.
(This is in direct contradiction to the general usage of those terms where "soft link" and "symbolic link" ("symlink") DO mean the same thing.)
I combined two answers (@bviktor and @jocassid). It was tested on Windows 10 and Windows Server 2012.
function New-SymLink ($link, $target){if ($PSVersionTable.PSVersion.Major -ge 5){New-Item -Path $link -ItemType SymbolicLink -Value $target}else{$command = "cmd /c mklink /d"invoke-expression "$command ""$link"" ""$target"""}}
You can use this utility:
c:\Windows\system32\fsutil.exe create hardlink
I wrote a PowerShell module that has native wrappers for MKLINK. https://gist.github.com/2891103
Includes functions for:
Captures the MKLINK output and throws proper PowerShell errors when necessary.
Actually, the Sysinternals junction
command only works with directories (don't ask me why), so it can't hardlink files. I would go with cmd /c mklink
for soft links (I can't figure why it's not supported directly by PowerShell), or fsutil
for hardlinks.
If you need it to work on Windows XP, I do not know of anything other than Sysinternals junction
, so you might be limited to directories.
I found this the simple way without external help. Yes, it uses an archaic DOS command but it works, it's easy, and it's clear.
$target = cmd /c dir /a:l | ? { $_ -match "mySymLink \[.*\]$" } | % `{$_.Split([char[]] @( '[', ']' ), [StringSplitOptions]::RemoveEmptyEntries)[1]}
This uses the DOS dir command to find all entries with the symbolic link attribute, filters on the specific link name followed by target "[]" brackets, and for each - presumably one - extracts just the target string.