When the plugin detects "not Unix" it will try to start powershell.exe. On Windows Nano Server there is only PowerShell Core available and the executable name there is pwsh.exe. Creating a hardlink or symlink named powershell.exe that links to pwsh.exe does not work because when you run powershell.exe (the link) the process exits with the message:

      The managed DLL bound to this executable: 'pwsh.dll', did not match own name 'powershell.dll'.
      A fatal error was encountered. This executable was not bound to load a managed DLL.

      This makes it currently impossible to use PS Core on Nano Server.

      One simple solution would be to detect Nano Server and then just run pwsh.exe like on Unix systems.

      When running Windows Server Core this gets a little more complicated because you can have both the regular PS and PS Core side by side, so a decision must be made about the behavior in this case.
      The options are:

      • If pwsh.exe is in PATH then always prefer it over the regular one
      • If regular powershell.exe is available then always prefer it over PS Core

      The first option makes the most sense to me because having both PS versions is not likely to happen and if you have them running side by side that's probably because you want PS Core to be used (if you want regular PS then just don't install PS Core in the first place).

          [JENKINS-52421] Support PowerShell Core on Windows-Systems

          esra added a comment -

          Are there any updates on this?

          esra added a comment - Are there any updates on this?

          Martin Bauer added a comment -

          The problem is a general one on Windows platforms.

          Currently it is not possible to use Powershell Core (currently version 6 and 7) with the Jenkins plugin on Windows machines.
          The version 5.1 (integrated in Windows) is always used. But this version is no longer developed and scripts may require newer versions of PS.

          There should be a possibility to use pwsh instead of powershell on Windows systems.

          The best would be to have two Build-Steps provided from the Plug-in on Windows Systems:
          Powershell
          and Powershell Core 

          Martin Bauer added a comment - The problem is a general one on Windows platforms. Currently it is not possible to use Powershell Core (currently version 6 and 7) with the Jenkins plugin on Windows machines. The version 5.1 (integrated in Windows) is always used. But this version is no longer developed and scripts may require newer versions of PS. There should be a possibility to use pwsh instead of powershell on Windows systems. The best would be to have two Build-Steps provided from the Plug-in on Windows Systems: Powershell and Powershell Core 

          Michael P added a comment - - edited

          I feel like a good all around solution would be to provide a dropdown for PowerShell Version Preference. I've thrown together a small POC:

           

          This solution solves multiple issues:

          • Running scripts that support both powershell and pwsh but may be run against multiple environments where one or the other may not be present
          • Running scripts that only support pwsh
          • Running scripts that only support powershell

           

          Michael P added a comment - - edited I feel like a good all around solution would be to provide a dropdown for PowerShell Version Preference. I've thrown together a small POC:   This solution solves multiple issues: Running scripts that support both powershell and pwsh but may be run against multiple environments where one or the other may not be present Running scripts that only support pwsh Running scripts that only support powershell  

          m1kep I really like your proposal. This would satisfy everyone.

          Julien Bouvier added a comment - m1kep I really like your proposal. This would satisfy everyone.

          Michael P added a comment -

          jbouvier I have a PR in the Github repository for the plugin(https://github.com/jenkinsci/powershell-plugin/pull/15). It will implement the following:

           

          There was some trouble searching the path for the executable, so the "Prefer" options were not implemented. The following lays outs the current settings:

          • OS Based
            • Checks if running on Windows, if so it uses powershell.exe
            • If not on Windows, it opts for pwsh.exe
          • Windows PowerShell
            • Uses powershell.exe
          • PowerShell Core
            • Uses pwsh.exe

           

          Michael P added a comment - jbouvier I have a PR in the Github repository for the plugin( https://github.com/jenkinsci/powershell-plugin/pull/15) . It will implement the following:   There was some trouble searching the path for the executable, so the "Prefer" options were not implemented. The following lays outs the current settings: OS Based Checks if running on Windows, if so it uses powershell.exe If not on Windows, it opts for pwsh.exe Windows PowerShell Uses powershell.exe PowerShell Core Uses pwsh.exe  

            Unassigned Unassigned
            stannieman Stan Wijckmans
            Votes:
            6 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: