KEMBAR78
New-Item: When creating symbolic links (symlinks) / reparse points, the -Target path should always be treated as a *literal* path · Issue #13136 · PowerShell/PowerShell · GitHub
Skip to content

New-Item: When creating symbolic links (symlinks) / reparse points, the -Target path should always be treated as a *literal* path #13136

@mklement0

Description

@mklement0

Note:

Summary of the new feature/enhancement

When you create a symlink or reparse point, you want to target a specific, literal target path - you're not looking for this path to determined via wildcard-pattern matching, which, however, is what currently happens: a -Target (-Value) argument is (invariably) interpreted as a wildcard pattern. What makes the behavior even less useful is that the pattern must resolve to exactly one path.

  • Interpreting the -Target (-Value) argument as a wildcard expression means that meant-to-be-literal paths such as [a].txt would mistakenly target a.txt, if present, for instance.

  • Also, as a potentially unwanted side effect, if the -Target (-Value) is determined via wildcard resolution, a relative input path (pattern) is invariably resolved to a full path.

The sensible behavior is to always treat the -Target (-Value) argument as a literal path (and to preserve its relative-vs.-full path status, as specified).


Once the change is implemented, the following tests - which currently fail - should succeed:

$null = New-Item 'file1', 'file[1]'

$targetRelative = 'file[1]'
$targetAbsolute = Join-Path $pwd.providerpath 'file[1]'

(New-Item -Type SymbolicLink fileL -Target $targetRelative).Target | Should -Be $targetRelative
(New-Item -Force -Type SymbolicLink fileL -Target $targetAbsolute).Target | Should -Be $targetAbsolute

The tests currently fail, because file[1] is interpreted as a wildcard pattern that happens to match file1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerCommittee-ReviewedPS-Committee has reviewed this and made a decisionIn-PRIndicates that a PR is out for the issueIssue-Enhancementthe issue is more of a feature request than a bugWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions