2

So I'm trying to create links with relative path with PowerShell, but I don't know why I'm getting differents results, I'm quite new with the command line in Windows, sorry if this is a dumb question. Here are some results I got:

C:\Windows\system32>cd /d D:\test\directory
D:\test\directory>mklink testlink ..\test.txt
symbolic link created for testlink <<===>> ..\test.txt
PS D:\test\directory> New-Item -ItemType SymbolicLink -Path .\testlinkpowershell -Target ..\test.txt
D:\test\directory>dir
01/05/2020  10:57 AM    <SYMLINK>      testlink [..\test.txt]
01/05/2020  10:59 AM    <SYMLINK>      testlinkpowershell [D:\test\test.txt]

The main problem is that if the letter of the drive changes the symbolic links won't work, but if I use mklink it works like a charm. I know that I could just use mklink but I want to know why it does not work in PowerShell.

2

Windows PowerShell simply does not support the creation of relative paths for symbolic links. So it resolves the path to an absolute one before creating the symbolic link.

In the newer PowerShell Core, they fixed this. See GitHub Issue

In PowerShell Core 7, you can now use New-Item to create a symbolic link with a relative path.

I have no idea whether they will ever port this back to Windows PowerShell 5.x. I doubt it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.