powershell -File refuses scripts that aren't named .ps1
args quoting · case
Affectspowershell 51, pwsh 7, windows
Fails asNOT A POWERSHELL SCRIPT
Mechanismextension dispatch
Safe fixshell matching suffix
Symptom
Section titled “Symptom”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.
Copy-Item installer.ps1 installer.shpowershell -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.
Workaround
Section titled “Workaround”- Choose the temp suffix by target shell:
.ps1when the launcher is PowerShell,.shfor POSIX. The referenced fix does exactly this (suffix = shell === ‘powershell’ ? ‘ps1’ : ‘sh’).