Skip to content

When New-Item -Path is combined with -Name, the -Path argument is inappropriately treated as a wildcard expression #17106

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

Note:

The following two statements should be equivalent, but aren't:

# OK - with only a -Path argument, the path is taken *literally*
# Creates a subdir. literally named '[test]' with a file 'test.txt' in it.
New-Item -Force -Path '[test]\test.txt'

# !! BROKEN - with -Name also present, the -Path argument is
# !! interpreted as a *wildcard expression*
New-Item -Force -Path '[test]' -Name 'test.txt'

With -Name also present, -Path is unexpectedly treated as a wildcard expression.

Expected behavior

Both commands should (re)create a subdirectory [test] with a file test.txt in it, and report a FileInfo instance for the latter; e.g.:

    Directory: /Users/jdoe/[test]

UnixMode   User             Group                 LastWriteTime           Size Name
--------   ----             -----                 -------------           ---- ----
-rw-r--r-- jdoe             staff                4/4/2022 17:08              0 test.txt

Actual behavior

The second command is situationally either a quiet no-op, or fails when wildcard pattern [test] matches an existing file named t or e or ... or inappropriately targets an existing directory named t or e ...

Error details

No response

Environment data

PowerShell Core 7.3.0-preview.3

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreWG-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