Skip to content

New-Item cannot create symlink/hardlink for file with name containing bracket #25744

@wumo

Description

@wumo

Prerequisites

Steps to reproduce

As for latest 7.5.2, the following error happened:

> Test-Path -LiteralPath "a\a[b].txt"
# return True
> New-Item -ItemType SymbolicLink -Path "a[b].txt" -Target "a\a[b].txt"
# New-Item: Cannot find path 'a\a[b].txt' because it does not exist.

Expected behavior

PS> New-Item -ItemType SymbolicLink -Path "a[b].txt" -Target "a\a[b].txt"

 Directory: E:\test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
la---           7/10/2025    02:24              0 a[b].txt -> a\a[b].txt

Actual behavior

PS> New-Item -ItemType SymbolicLink -Path "a[b].txt" -Target "a\a[b].txt"

New-Item: Cannot find path 'a\a[b].txt' because it does not exist.

Error details

Environment data

PS > $PSVersionTable

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions