Skip to content

Set/Add-Content doesn't work with paths with escaped wildcards characters #9588

@daxian-dbw

Description

@daxian-dbw

Steps to reproduce

PS> New-Item [out].txt

Directory: F:\tmp\modules\temp

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         5/13/2019  9:29 AM              0 [out].txt

PS> Set-Content -Path '.\`[out`].txt' -Value "value"
Set-Content : An object at the specified path .\`[out`].txt does not exist, or has been filtered by the -Include or -Exclude parameter.
At line:1 char:1
+ Set-Content -Path '.\`[out`].txt' -Value "value"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Set-Content], Exception
+ FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.SetContentCommand

PS> Add-Content -Path '.\`[out`].txt' -Value "value"
Add-Content : An object at the specified path .\`[out`].txt does not exist, or has been filtered by the -Include or -Exclude parameter.
At line:1 char:1
+ Add-Content -Path '.\`[out`].txt' -Value "value"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Add-Content], Exception
+ FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.AddContentCommand

Expected behavior

Clear-Content and Get-Content work fine with the same path

PS> Get-Content -Path '.\`[out`].txt'
Content
PS:114> Clear-Content -Path '.\`[out`].txt'
PS:115> dir

    Directory: F:\tmp\modules\temp

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----         5/13/2019  9:32 AM              0 [out].txt

Set-Content and Add-Content should also work with that path.

Actual behavior

Add-Content and Set-Content don't work with the path.

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-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