The term 'powershell.exe' is not recognized as the name of a cmdlet in VSTS Task

Viewed 11489

All of sudden I m getting the error

"2018-08-30T06:19:30.8460321Z ##[error]The term 'powershell.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. " while executing PS task in VSTS .

My PS task has simple Write-Host $variable statement, it worked till y'day and something went wrong, tried rebooting target machine, ensured PS is available etc.

Any debugging steps please ?

enter image description here

5 Answers

Just in case somebody gets this error message on a hosted vm. I had the same issue and it was caused by a Pipeline variable called "Path". So just be smarter than me and don't name your variables like that.

This is what you definitely should avoid:

Refer to these steps:

  1. Check Path variable of System variables
  2. By default, there is %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ item, if it isn’t existing, please add related path that contains PowerShell.exe to the Path variable
  3. Restart your machine.

Check the environment variables on the machine - the "Path" variable should have the path to the Windows PowerShell directory in system32

Environment Variables - Path

Issue was with Inline PS script, any script error throws .

The term 'powershell.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Created a new release definition and it worked

So I noticed that release definitions created before is not having the same issue but if I add a new VSTS-task for PowerShell (Microsoft version) to a release definition it is unable to recognize powershell. I am wondering whether they pushed a change to the task and it broke something. My agent path directory is correct.

As an alternative, I am using a 3rd party developer's task. https://thinkrethink.net/2016/05/20/using-the-inline-powershell-vsts-task/

Related