Skip to content

PowerShell 7 is unable to create a junction on relative paths while PS 5 can #15750

Closed

Description

@superbonaci

Prerequisites

Steps to reproduce

Try to create a junction with powershell 7:

PS E:\> mkdir 'Program Files (x86)\Steam'
PS E:\> New-Item -ItemType Junction -Path 'C:\Program Files (x86)\Steam' -Target 'Program Files (x86)\Steam\'

Expected behavior

Create the symlink in PS7 like in PS 5.

Actual behavior

Gives error:
New-Item: Could not find item Program Files (x86)\Steam\.

Error details

No response

Environment data

This version does not create the symlink:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

This version DOES work:

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1023
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1023
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


### Visuals

_No response_

Activity

  1. added
    Needs-Triage
    on Jul 10, 2021
  2. 237dmitry commented on Jul 10, 2021

    @237dmitry

    I think you confused the Path with the Target

  3. superbonaci commented on Jul 11, 2021

    @superbonaci
    Author

    237dmitry no I didn't, because the folder C:\Program Files (x86)\Steam was moved to another drive.
    Similar bug: #6232

  4. superbonaci commented on Jul 11, 2021

    @superbonaci
    Author

    Finally found the problem. PowerShell 7 can't work with relative paths when creating junctions on directories. However PS5 can. So to fix it, you must provide always a full path. So with a full path works with PS 5 and PS 7, and you can use Target or Value both work.

    Either way it works now. Remember to run powershell as admin which can be required:

    New-Item -ItemType Junction -Path 'C:\Program Files (x86)\Steam' -Value  (Get-Item 'Program Files (x86)\Steam\').FullName
    New-Item -ItemType Junction -Path 'C:\Program Files (x86)\Steam' -Target (Get-Item 'Program Files (x86)\Steam\').FullName
    
  5. changed the title [-]PowerShell 7 is unable to create a junction while PS 5 can[/-] [+]PowerShell 7 is unable to create a junction on relative paths while PS 5 can[/+] on Jul 11, 2021
  6. rkeithhill commented on Jul 11, 2021

    @rkeithhill
    Collaborator

    I think you are running into an issue where relative symlink paths are relative to the process's (not the PS file system provider's) current working dir. See #15235 (comment)

  7. superbonaci commented on Jul 11, 2021

    @superbonaci
    Author

    Yeah but something changed too much if works with PS5 and not with PS7. This is kind of incompatibility thing which shouldn't happen I guess...

  8. rkeithhill commented on Jul 11, 2021

    @rkeithhill
    Collaborator

    This is kind of incompatibility thing which shouldn't happen

    Agreed but unfortunately regressions happen, and often when someone has the good intention of fixing some bug or implementing an enhancement request.

  9. superbonaci commented on Jul 11, 2021

    @superbonaci
    Author

    Yeah the idea if that's a regression or done on purpose.

  10. added
    Area-FileSystem-Provider
    Resolution-Duplicate
    on Jul 12, 2021
  11. ghost closed this as completedon Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-ProviderNeeds-TriageResolution-Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions