0
votes

I'm following this tutorial to automate the creation of release notes using the wiki in Azure DevOps. Steps are very basic and there are not many variables that I believe would cause the error.

enter image description here

When I create a release it runs and then fails at the PowerShell task. This is what is displayed in the log and with the error:

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

I have replaced my agent name with [myLocalAgent] in the log

2020-03-10T08:46:58.0567080Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2020-03-10T08:46:58.0567721Z ##[debug]Evaluating: succeeded()
2020-03-10T08:46:58.0567840Z ##[debug]Evaluating succeeded:
2020-03-10T08:46:58.0568071Z ##[debug]=> True
2020-03-10T08:46:58.0568346Z ##[debug]Result: True
2020-03-10T08:46:58.0568583Z ##[section]Starting: PowerShell Script
2020-03-10T08:46:58.0660872Z ==============================================================================
2020-03-10T08:46:58.0660963Z Task         : PowerShell
2020-03-10T08:46:58.0661006Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2020-03-10T08:46:58.0661050Z Version      : 2.165.0
2020-03-10T08:46:58.0661103Z Author       : Microsoft Corporation
2020-03-10T08:46:58.0661147Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2020-03-10T08:46:58.0661190Z ==============================================================================
2020-03-10T08:46:59.2751397Z ##[debug]VstsTaskSdk 0.11.0 commit 7ff27a3e0bdd6f7b06690ae5f5b63cb84d0f23f4
2020-03-10T08:46:59.4510283Z ##[debug]Entering C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\powershell.ps1.
2020-03-10T08:46:59.4641263Z ##[debug]Loading resource strings from: C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\task.json
2020-03-10T08:46:59.5013258Z ##[debug]Loaded 11 strings.
2020-03-10T08:46:59.5070774Z ##[debug]SYSTEM_CULTURE: 'en-US'
2020-03-10T08:46:59.5667676Z ##[debug]Loading resource strings from: C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\Strings\resources.resjson\en-US\resources.resjson
2020-03-10T08:46:59.6018496Z ##[debug]Loaded 11 strings.
2020-03-10T08:46:59.6361663Z ##[debug]INPUT_ERRORACTIONPREFERENCE: 'stop'
2020-03-10T08:46:59.6401971Z ##[debug]INPUT_FAILONSTDERR: 'false'
2020-03-10T08:46:59.6440102Z ##[debug] Converted to bool: False
2020-03-10T08:46:59.6470870Z ##[debug]INPUT_IGNORELASTEXITCODE: 'false'
2020-03-10T08:46:59.6491840Z ##[debug] Converted to bool: False
2020-03-10T08:46:59.6521051Z ##[debug]INPUT_PWSH: 'false'
2020-03-10T08:46:59.6543374Z ##[debug] Converted to bool: False
2020-03-10T08:46:59.6572719Z ##[debug]INPUT_WORKINGDIRECTORY: 'C:\[myLocalAgent]\_work\r7\a'
2020-03-10T08:46:59.6748678Z ##[debug]Asserting container path exists: 'C:\[myLocalAgent]\_work\r7\a'
2020-03-10T08:46:59.6782331Z ##[debug]INPUT_TARGETTYPE: 'inline'
2020-03-10T08:46:59.6826977Z ##[debug]INPUT_SCRIPT: '# Get content of releasenotes
2020-03-10T08:46:59.6841501Z ##[debug]$content = [IO.File]::ReadAllText("C:\[myLocalAgent]\_work\r7\a\releasenotes.md")
2020-03-10T08:46:59.6855896Z ##[debug]# Get content of package.json for getting version value
2020-03-10T08:46:59.6870421Z ##[debug]$contentPackage = [IO.File]::ReadAllText("C:\[myLocalAgent]\_work\r7\a\package.json") | ConvertFrom-Json;
2020-03-10T08:46:59.6884843Z ##[debug]# Concat the URI
2020-03-10T08:46:59.6900257Z ##[debug]$uri = $env:WikiUri +$env:WikiPath + $($contentPackage.version)
2020-03-10T08:46:59.6916667Z ##[debug]# Convert to json for Wiki API
2020-03-10T08:46:59.6932043Z ##[debug]$data = @{content=$content;} | ConvertTo-Json;
2020-03-10T08:46:59.6947112Z ##[debug]# Set Request
2020-03-10T08:46:59.6960317Z ##[debug]$params = @{uri = "$($uri)";
2020-03-10T08:46:59.6973489Z ##[debug]  Method = 'PUT';
2020-03-10T08:46:59.6986730Z ##[debug]  Headers = @{Authorization = "Basic $($env:basicB64Token)" };
2020-03-10T08:46:59.7000064Z ##[debug]  ContentType = "application/json";
2020-03-10T08:46:59.7013085Z ##[debug]  Body = $data;
2020-03-10T08:46:59.7026111Z ##[debug]}
2020-03-10T08:46:59.7039918Z ##[debug]# Call 
2020-03-10T08:46:59.7053974Z ##[debug]Invoke-WebRequest @params'
2020-03-10T08:46:59.7136093Z Generating script.
2020-03-10T08:46:59.7346195Z ##[debug]AGENT_VERSION: '2.154.3'
2020-03-10T08:46:59.7464794Z ##[debug]AGENT_TEMPDIRECTORY: 'C:\[myLocalAgent]\_work\_temp'
2020-03-10T08:46:59.7490309Z ##[debug]Asserting container path exists: 'C:\[myLocalAgent]\_work\_temp'
2020-03-10T08:46:59.8394063Z ##[debug]Leaving C:\[myLocalAgent]\_work\_tasks\PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1\2.165.0\powershell.ps1.
2020-03-10T08:46:59.8447996Z ##[debug]Caught exception from task script.
2020-03-10T08:46:59.8484660Z ##[debug]Error record:
2020-03-10T08:46:59.9086805Z ##[debug]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.
2020-03-10T08:46:59.9099083Z ##[debug]    + CategoryInfo          : ObjectNotFound: (powershell.exe:String) [], Comm    andNotFoundException
2020-03-10T08:46:59.9111398Z ##[debug]    + FullyQualifiedErrorId : CommandNotFoundException
2020-03-10T08:46:59.9124155Z ##[debug] 
2020-03-10T08:46:59.9147270Z ##[debug]Script stack trace:
2020-03-10T08:46:59.9203751Z ##[debug]
2020-03-10T08:46:59.9225885Z ##[debug]Exception:
2020-03-10T08:46:59.9278832Z ##[debug]System.Management.Automation.CommandNotFoundException: 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.
2020-03-10T08:46:59.9656113Z ##[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.
2020-03-10T08:46:59.9666068Z ##[debug]Processed: ##vso[task.logissue type=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.
2020-03-10T08:46:59.9666747Z ##[debug]Processed: ##vso[task.complete result=Failed]

I have searched on the web and there are references to incorrect spelling due to spaces in the file name (no spaces in my file names) or an incorrect path that is referenced (my PowerShell is inline/autogenerated).

Would appreciate any assistance.

Thank you in advance.

2

2 Answers

0
votes

What OS are you running? What PowerShell version are you running? What it's in your environment path?

There are three executables for PowerShell on Windows

  1. PowerShell console = powershell.exe
  2. PowerShell ide = powershel_ise.exe
  3. Powershell core = pwsh.exe

There is only one executable for PowerShell on OSX/*Nix

  1. Powershell core = pwsh.exe

Anytime you see stuff like, The term 'XXX' 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.', it's normally always and install/config issue regardless of whatever command you are trying to use regardless of OS version.

0
votes

Error on PowerShell task in Azure DevOps: The term 'powershell.exe' is not recognized as the name

Since you are using your private agent, please check following:

First, Check Path variable of System variables, 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, then restart your machine.

Second, avoid use "Path" in the Pipeline variable:

enter image description here

Third, try to test it with hosted agent to check if the error comes from the powershell scripts itself.

Hope this help.