Search code examples
powershellazure-devopsazure-pipelines

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!


Solution

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