Skip to content

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

Closed

Description

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

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    and removed
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on May 13, 2019
  2. mklement0 commented on Nov 7, 2019

    @mklement0
    Contributor

    Related:

    Overall, though technically a breaking change, I think the right answer is to treat all output file paths as literals.

    Use of wildcard patterns in these scenarios is unexpected, mostly useless and always fraught.

  3. 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.

  4. 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.

  5. 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.

  6. 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

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions