Need ability to make a PowerShell Core script "automatically" run under PowerShell Core on Windows
See original GitHub issueIf my script requires
PowerShell Core to run, then on Windows there is no good way to invoke a .ps1 file (say from cmd.exe or Win+r) and have Windows pick the correct version of PowerShell (PS Core or Win PS). So yeah, this scenario requires that folks configure the Open
verb to execute the PS1 file extension. And there can only be one exe for “Open”: either powershell.exe or pwsh.exe.
Another scenario is that you have a build system without support for PowerShell Core yet. It runs Windows PowerShell. It would be nice if Windows PowerShell could fire off the appropriate version of PowerShell Core installed on the system if it sees #requires -Version 6
in the script. Although using a version for this is less than satisfying. It would be better in this case to have an edition requirement as well e.g.:
#Requires -Edition Core -Version 6.1.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (7 by maintainers)
#requires
tells you when you’re doing it wrong with an error.Shebang runs the right version of PowerShell for you implicitly (assuming you specified the right path of course.)
I’m not saying we can get shebang into Windows, but I still think it’s what you’re looking for.
@SteveL-MSFT if we took a page from the PHP handbook,
.ps6
is a good idea.If we took a page from the Python Handbook, we wouldn’t do anything at all with file extensions. New extensions become messy and make for transitions between versions supporting multiple versions painful. I realize it would be coercive in the “you must use
.ps6
for core” sense, but as people begin to adopt it you start getting modules and projects with mixed extensions. Python ultimately went with the assumption that users would just have to know what they’re doing.In any case, I would urge that the decision to add a new extension not be taken lightly. It may be simplest in implementation, but it could have a massive and lasting impact on the PowerShell ecosystem as a whole.