If the PowerShell v2 task runs on Linux/Mac it uses PowerShell Core automatically but on Windows, it uses Windows PowerShell.
There should be something like a checkbox available to Run using PowerShell Core that makes it use PowerShell Core on Windows and the value of this checkbox gets ignored on other systems.
What issue does it cause to have it run by PowerShell on windows?
Apart from the fact that PowerShell Core is twice as fast, it has also an improved engine and new capabilities such as e.g. cross platform remoting.
Calling pwsh.exe from Windows PowerShell is not a pleasure due to various problems and therefore solutions to command line parsing. It is annoying having to escape stuff or having to encode the command.
Also, Windows PowerShell is not side by side. If a local agent on a system under test only has PowerShell v3 (which cannot be upgraded in order to truly test that software works with that configuration), then the experience is pretty bad. PowerShell Core is self contained and side by side with no side effects.
Also read what the community and MSFT people say: https://twitter.com/DonovanBrown/status/1005918563343970314?s=19
Cc @stevel-msft
I'll leave this open and have someone dig into it.
If a user is authoring a cross platform PowerShell script (doing builds, running tests) across Linux, Windows, and macOS. Currently they have to special case Windows PowerShell because there have been breaking changes and new capabilities we've taken in PowerShell Core. What @bergmeister is saying is to have PowerShell Core as an option on Windows which runs happily side-by-side with Windows PowerShell with no conflict so that a single script can work across all three platforms.
I should mention that adding PSCore6 to the Windows image can be as simple as using the .zip we publish and updating the system PATH env var so that pwsh is found.
Doesn't the change here mean that PowerShell Core is preferred if present on the Windows Agent in version 2 of the task?
No that is the version that runs on Linux/macOS.
If you are on Windows it will always go to PowerShell.exe, it will only look for pwsh on Mac and Linux.
We have discussed adding a bool “pwsh: true” to enable Windows users to require pwsh. Does that sound good?
Ah right. @ericsciple that would work great for us!
@ericsciple Any updates on this?
I have found a fix and will submit a PR for this
Is there a workaround in the meantime? Is pwsh installed on the Windows agents, so that we can run pwsh -c manually? I have a C# cmdlet that only runs on PowerShell Core because a dependency requires .NET Core 2.1 and can't target .NET Standard 2.0 (nor .NET Framework).
@felixfbecker Yes, you can call pwsh -command or pwsh -file from any task that takes a command line option or just from Windows PowerShell.
- task: PowerShell@2
inputs:
#targetType: 'inline'
script: '# Write your powershell commands here.'
pwsh: true
Setting pwsh as true enables Powershell Core
Most helpful comment
I have found a fix and will submit a PR for this