Skip to content

PowerShell CLI: Consider allowing passing extension-less script files to -File on Windows again. #26584

@mklement0

Description

@mklement0

Summary of the new feature / enhancement

Up to PowerShell 7.1.x, pwsh -File someScriptWithoutExtension - which works on Unix to this day - also worked on Windows (whereas the by-definition Windows-only Windows PowerShell always required -File arguments to have extension .ps1).

In PS 7.2, this was reverted with a stated rationale of, "[...] Windows doesn't support shebang, so we should be consistent with Windows PowerShell and only allow for scripts with .ps1 extension."

Allowing extension-less script-file names is crucial for properly supporting stand-alone, directly executable PowerShell scripts using a shebang line on Unix, such as #!/usr/bin/env pwsh

However, even on Windows this can be important, namely in mixed environments such as Git Bash:
In order to be able to use PowerShell to implement Git hook scripts, which are shebang-line based and all have extension-less names (e.g., pre-commit), pwsh.exe's (positionally implied) -File parameter would have to accept extension-less script paths (which it did until 7.1.x)

Please consider reverting the above-mentioned change (which again would allow not only extension-less files but files with any extension, as currently implemented on Unix platforms), given the following:

  • Git is a widely used tool, so facilitating direct PowerShell use is desirable (the alternatives / workarounds, show in this Stack Overflow answer, are suboptimal); the popularity of this Stack Overflow post shows there's significant community interest.

  • Retaining strict consistency with Windows PowerShell doesn't seem important in this case: backward compatibility is ensured (passing script paths with .ps1 extensions will continue to work); it is a merely a new capability that is added.

  • Windows PowerShell's restrictive behavior was arguably never a good idea to begin with: users can be expected to know that only files containing PowerShell code can be passed to pwsh -File, irrespective of the file's extension, as modeled by all major POSIX-compatible shells; e.g. bash somefile.withrandomextension works just fine, as long as said file contains Bash code.

Proposed technical implementation details (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.WG-NeedsReviewNeeds a review by the labeled Working GroupWG-Securitysecurity related areas such as JEA

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions