Skip to content

New-Item -ItemType Junction- can't create functioning relative links #12785

Closed

Description

Steps to reproduce

Follow example 7 here: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-7powershell!

  1. Create a folder eg. named "power"
  2. In this (power) folder create an empty folder named "Notice"
  3. In this (power) folder create a file named "Notice.txt"
  4. As admin run this script:
    New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
    New-Item -ItemType Junction -Path .\link -Target .\Notice -Force

Expected behavior

Create two functioning links for both a file and a folder

Actual behavior

PS C:\retus\test2Die\power problems> .\test.ps1
New-Item: C:\retus\test2Die\power problems\test.ps1:1
Line |
1 | New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
|
| Could not find item .\Notice.txt.

New-Item: C:\retus\test2Die\power problems\test.ps1:3
Line |
3 | New-Item -ItemType Junction -Path .\link -Target .\Notice -Force
|
| Could not find item .\Notice.
#NOTE

Works with absolute path

Environment data

PS C:\retus\test2Die\power problems> $psversiontable

Name Value


PSVersion 7.1.0-preview.3
PSEdition Core
GitCommitId 7.1.0-preview.3
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on May 25, 2020
  2. KalleOlaviNiemitalo commented on May 25, 2020

    @KalleOlaviNiemitalo

    AFAIK, Windows supports directory junctions but not file junctions. PowerShell 7.1.0-preview.3 outputs a saner error message than PowerShell 7.0.0, but both lose to Windows PowerShell 5.1.

    PowerShell 7.1.0-preview.3

    PS C:\temp\power> New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
    New-Item: Could not find item .\Notice.txt.
    PS C:\temp\power> New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\temp\power\Notice.txt
    New-Item: A directory is required for the operation. The item 'C:\temp\power\Notice.txt' is not a directory.
    PS C:\temp\power> New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\temp\power\doesnotexist.txt
    New-Item: Cannot find path 'C:\temp\power\doesnotexist.txt' because it does not exist.
    PS C:\temp\power> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      7.1.0-preview.3
    PSEdition                      Core
    GitCommitId                    7.1.0-preview.3
    OS                             Microsoft Windows 10.0.18363
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    

    PowerShell 7.0.0

    PS C:\temp\power> New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
    New-Item: Could not find item {0}.
    PS C:\temp\power> New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\temp\power\Notice.txt
    New-Item: A directory is required for the operation. The item 'C:\temp\power\Notice.txt' is not a directory.
    PS C:\temp\power> New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\temp\power\doesnotexist.txt
    New-Item: Cannot find path 'C:\temp\power\doesnotexist.txt' because it does not exist.
    PS C:\temp\power> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      7.0.0
    PSEdition                      Core
    GitCommitId                    7.0.0
    OS                             Microsoft Windows 10.0.18363
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    

    Windows PowerShell 5.1

    PS C:\temp\power> New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
    New-Item : A directory is required for the operation. The item 'C:\temp\power\Notice.txt' is not a directory.
    At line:1 char:1
    + New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (C:\temp\power\Notice.txt:String) [New-Item], InvalidOperationExceptio
       n
        + FullyQualifiedErrorId : ItemNotDirectory,Microsoft.PowerShell.Commands.NewItemCommand
    
    PS C:\temp\power> New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\temp\power\Notice.txt
    New-Item : A directory is required for the operation. The item 'C:\temp\power\Notice.txt' is not a directory.
    At line:1 char:1
    + New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\t ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (C:\temp\power\Notice.txt:String) [New-Item], InvalidOperationExceptio
       n
        + FullyQualifiedErrorId : ItemNotDirectory,Microsoft.PowerShell.Commands.NewItemCommand
    
    PS C:\temp\power> New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\temp\power\doesnotexist.txt
    New-Item : Cannot find path 'C:\temp\power\doesnotexist.txt' because it does not exist.
    At line:1 char:1
    + New-Item -ItemType Junction -Path C:\temp\power\link.txt -Target C:\t ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (C:\temp\power\doesnotexist.txt:String) [New-Item], ItemNotFoundExceptio
       n
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemCommand
    
    PS C:\temp\power> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.18362.752
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.18362.752
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    

    Windows PowerShell 2.0

    Does not support New-Item -ItemType Junction.

  3. KalleOlaviNiemitalo commented on May 25, 2020

    @KalleOlaviNiemitalo
    PS C:\temp\power> New-Item -ItemType Junction -Path .\link.txt -Target .\Notice.txt
    New-Item: Could not find item .\Notice.txt.
    

    Process Monitor and WinDbg show that PowerShell 7.1.0-preview.3 is calling GetFileAttributesExW on Notice.txt in the current directory of the process as shown by [Environment]::CurrentDirectory, not in the directory that I selected with Set-Location.

    Perhaps FileSystemProvider.NewItem is calling GetFileSystemInfo with a relative path and it needs an absolute path. If I bypass the #8783 change by using a wildcard in -Target, then PowerShell 7.1.0-preview.3 gives the correct error message:

    PS C:\temp\power> New-Item -ItemType Junction -Path .\link.txt -Target .\Notic*.txt
    New-Item: A directory is required for the operation. The item 'C:\temp\power\Notice.txt' is not a directory.
    
  4. iSazonov commented on May 26, 2020

    @iSazonov
    Collaborator

    Dup Related #12784

  5. sukkergris commented on Jun 3, 2020

    @sukkergris
    Author

    Ilya (@iSazonov) - Not sure why this is considered a dup of #12784. One i targeted junctions and the other targeted symlinks and each bug has different symptoms :)

  6. iSazonov commented on Jun 3, 2020

    @iSazonov
    Collaborator

    My thoughts was that it will be fixed in the same place but I am ok to re-open.

  7. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    and removed on Jun 3, 2020
  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

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-Providerspecific to the FileSystem providerIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions