Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute Powershell script with powershell instead of pwsh #13

Open
FH-Inway opened this issue Jan 7, 2024 · 2 comments
Open

Execute Powershell script with powershell instead of pwsh #13

FH-Inway opened this issue Jan 7, 2024 · 2 comments

Comments

@FH-Inway
Copy link

FH-Inway commented Jan 7, 2024

While playing around with my fork, I noticed that the task for Powershell scripts executes them with Powershell 7 (pwsh.exe) on a Windows runner.

The following implicates that this should only happen when the pwsh parameter is true.

{
"name": "pwsh",
"type": "boolean",
"label": "Use PowerShell Core",
"required": false,
"defaultValue": "false",
"helpMarkDown": "If this is true, then on Windows the task will use pwsh.exe from your PATH instead of powershell.exe.",
"groupName": "advanced"
},

I believe this is a bug that was copied over from https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/PowerShellV2/powershell.ts, since both that logic and https://github.com/cloudpups/authenticated-scripts/blob/main/tasks/powershell/execute-cli.ts do not make use of the pwsh parameter. The Microsoft task is not affected by that bug, because it uses https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/PowerShellV2/powershell.ps1 when the task is executed on a Windows runner. That script considers the pwsh parameter.

I made a change on my fork to address that issue, but it would require some additional work to bring it over to this repo (mainly to add logic to check if the task is running on Windows or not).

If there is interest for that, I can try creating a pull request.

@JoshuaTheMiller
Copy link
Member

@FH-Inway- if you can find the time to port those changes over, please do so 😀 copying over the bug itself was definitely an oversight, and one I had not ran into with my own use. This will be helpful for others too!

FH-Inway added a commit to FH-Inway/authenticated-scripts that referenced this issue Jan 13, 2024
…dows

fixes Execute Powershell script with powershell instead of pwsh cloudpups#13
@FH-Inway
Copy link
Author

@JoshuaTheMiller See #14

Note this changes the behavior of the PowerShell task on Windows, because by default, it will now use powershell.exe (i.e. PowerShell 5) instead of pwsh.exe (PowerShell 7). If this causes an issue, it can be easily fixed by setting the pwsh parameter of the task to true, which restores the previous behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants