Skip to content

New-Item -ItemType SymbolicLink should support creating symlinks with relative paths #3500

Closed

Description

Being able to create symlinks using relative paths is an important feature that both the ln utility on Unix and cmd's built-in command mklink on Windows support.

Currently, PowerShell invariably resolves the specified path to an absolute path when a symlink is created.
(#801 brought us the ability to create symlinks to non-existing targets, but even they are invariably resolved to an absolute path when the symlink is created).

Instead, the symlink should be defined with the target path exactly as specified.

Steps to reproduce (Unix)

$null = New-Item -ItemType SymbolicLink /tmp/$PID -Target ./foo -Force
readlink /tmp/$PID

Expected behavior

./foo

The symlink should be defined with the target path exactly as specified.

Actual behavior

/Users/jdoe/foo

The symlink was unexpectedly defined with an absolute path.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.17) on Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64

Activity

  1. added
    WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassif
    on Apr 7, 2017
  2. elca-lan commented on Jan 25, 2019

    @elca-lan

    Some official comment would be helpful here. I just ran into this issue and I must say, in most scenarios that I have so far encountered (e.g. symlinks in git repositories) absolute symlinks are not exactly very helpful.

    On Windows, I can still work around the issue by calling out to cmd /C mklink /D mylink .\mytarget but this really seems like a fairly fundamental flaw in the cmdlet.

  3. mklement0 commented on Jan 25, 2019

    @mklement0
    ContributorAuthor

    Agreed, elca-lan. Steve Lee (@SteveL-MSFT), perhaps this can be marked as up-for-grabs?

    On Unix-like platforms the workaround is to use ln -s ./mytarget mylink.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions