LoganCodes
LoganCodes

Reputation: 123

Issue with AzurePowerShell@5 task: 'The term 'pwsh.exe' is not recognized as the name of a cmdlet, function, script file, or operable program."

I'm seeing some weird behavior when trying to use the AzurePowerShell@5 task in my ADO pipeline. Below is how I have the task configured:

- task: AzurePowerShell@5
  inputs:
    azureSubscription: 'xyz'
    azurePowerShellVersion: LatestVersion
    pwsh: true
    ScriptType: filePath
    ScriptPath: 'pathName'
    ScriptArguments: >
    (args)

Note that I set pwsh: true which instructs the task to use PowerShell Core rather than Windows PowerShell. I have verified that the latest version of PowerShell 7 is installed by running winget install --id Microsoft.PowerShell on the virtual machine that is used to run my pipeline. I also verified it was added to the System Path environment variable list correctly (C:\Program Files\PowerShell\7\ is in my path).

Despite all this, I am still getting the error message in the title:

The term 'pwsh.exe' is not recognized as the name of a cmdlet, function, script file, or operable program

To add even more confusion, the same task works in a separate pipeline that uses a different virtual machine. The System PATH environment variable on both machines have PowerShell 7 and Windows PowerShell in the list. The only noticeable difference between the two machines is that the working machine is running Windows Server 2019 Standard, while the problematic machine is running Windows 10 Enterprise. Is Windows 10 Enterprise somehow incompatible with this task?

Any suggestions would be much appreciated!

Upvotes: 0

Views: 1999

Answers (2)

goToDino
goToDino

Reputation: 46

Same issue here. Restarted the ADO Agent service. will solve the issue

This will (re)load recently updated environment variables. The path to pwsh.exe must be set in machines` PATH variable. This will normally be done by the powershell installer itself

BUT

already running agents will not be aware of that

-> RESTART service or interactive agent

Upvotes: 1

LoganCodes
LoganCodes

Reputation: 123

I managed to get this working. I'm not sure which of the suggestions below was the solution--perhaps it was a combination of some. Regardless, as suggested in the comments above, I

  • Added the path for PowerShell 7 to the System PSModulePath environment variable
  • Added the path for PowerShell 7 to the User Path environment variable.
  • Restarted the ADO Agent service.

Upvotes: 0

Related Questions