question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need ability to make a PowerShell Core script "automatically" run under PowerShell Core on Windows

See original GitHub issue

If 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:open
  • Created 6 years ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
lzybkrcommented, Oct 21, 2017

#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.

1reaction
markekrauscommented, Oct 20, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installing PowerShell on Windows
For best results, install PowerShell to the to $env:ProgramFiles\PowerShell\7 folder. Install as a .NET Global tool. If you already have the .
Read more >
Getting Started with PowerShell Core on Windows, Mac ...
To get started with PowerShell Core you want to install and configure these three items on your operating system(s) of choice:.
Read more >
How to Write and Run Scripts in the Windows PowerShell ISE
This article describes how to create, edit, run, and save scripts in the Script Pane.
Read more >
about Scripts - PowerShell
Describes how to run and write scripts in PowerShell.
Read more >
Starting Windows PowerShell
In Windows Command shell, Windows PowerShell, or Windows PowerShell ISE, to start Windows PowerShell, type: PowerShell . You can also use the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found