Skip to content

powershell -File refuses scripts that aren't named .ps1

args quoting · case

bothhard-errorscriptcifirst-partyrepro: verifiedextension-dispatch
Affectspowershell 51, pwsh 7, windows
Fails asNOT A POWERSHELL SCRIPT
Mechanismextension dispatch
Safe fixshell matching suffix

A bootstrap downloads an installer script to a temp file and runs it with powershell -File $tmpfile. On Windows it fails with “the file … is not recognized as a PowerShell script” — because the temp file was created with a .sh (or extensionless) name by cross-platform code.

Terminal window
Copy-Item installer.ps1 installer.sh
powershell -File .\installer.sh
# Processing -File 'installer.sh' failed: the file does not have a '.ps1' extension.

powershell -File / pwsh -File dispatch on the FILENAME EXTENSION, not the content. Anything not ending in .ps1 is rejected before parsing. Cross-platform download helpers that default temp suffixes to .sh silently arm this on the Windows branch.

  • Choose the temp suffix by target shell: .ps1 when the launcher is PowerShell, .sh for POSIX. The referenced fix does exactly this (suffix = shell === ‘powershell’ ? ‘ps1’ : ‘sh’).