3
votes

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
Are you using a VSTS hosted agent (or) your own agent?Jayendran
Hello. My own agentuser2153844
Then the below answer might be work for you i guess! Isn't it?Jayendran
Path exists but it gives same error .user2153844
Did the normal powershell.exe in the cmd works within your agent ?Jayendran

5 Answers

12
votes

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:

3
votes

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.
2
votes

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

Environment Variables - Path

0
votes

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/

0
votes

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