Skip to content

Output-to-file cmdlets should not support wildcards with -Path #6714

@mklement0

Description

@mklement0

Note: This is technically a breaking change; if it is deemed too risky, keep it on file for PowerShell vNext.

Currently, output-to-file cmdlets such as Out-File and Set-Content do support wildcard expression passed to their -Path parameter.

This behavior is problematic in two respects:

  • Overwriting existing files should be a very deliberate act; the use of wildcards to target whatever happens to match contradicts that.

  • The utility of targeting an output file implicitly by wildcard is very limited:

    • If no existing file matches the wildcard expressions, an error occurs.
    • If more than one file matches the wildcard expression, the behavior is inconsistent:
      • With some cmdlets, an error occurs (e.g., Out-File, Export-FormatData
        • In other words: only if the wildcard expression happens to match one existing file does the operation succeed - at which point the clearer and safer choice is to target that file with a literal path.
      • Other cmdlets (e.g.Set-Content) output to all matching files, which is also problematic.

Ergo: output-to-file cmdlets should treat -Path as an alias of -LiteralPath (similar to how -Path in New-Item is effectively -LiteralPath).

Environment data

Written as of:

PowerShell Core v6.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions