首页 > 解决方案 > Azure DevOps 中的 PowerShell 任务出错:术语“powershell.exe”未被识别为名称

问题描述

我正在按照本教程使用 Azure DevOps 中的 wiki 自动创建发行说明。步骤非常基本,我认为不会导致错误的变量不多。

在此处输入图像描述

当我创建一个版本时,它会运行,然后在 PowerShell 任务中失败。这是日志中显示的内容并带有错误:

[错误] 术语“powershell.exe”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。

我在日志中用[myLocalAgent]替换了我的代理名称

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]

我在网上搜索过,由于文件名中的空格(我的文件名中没有空格)或引用的路径不正确(我的 PowerShell 是内联/自动生成的),所以引用了不正确的拼写。

将不胜感激任何帮助。

先感谢您。

标签: powershellazure-devopsazure-pipelinesazure-pipelines-tasksrelease-notes

解决方案


你在运行什么操作系统?您正在运行哪个 PowerShell 版本?它在你的环境路径中是什么?

Windows 上的 PowerShell 有三个可执行文件

  1. PowerShell 控制台 = powershell.exe
  2. PowerShell ide = powershel_ise.exe
  3. Powershell 核心 = pwsh.exe

在 OSX/*Nix 上只有一个 PowerShell 可执行文件

  1. Powershell 核心 = pwsh.exe

每当您看到类似的内容时,“XXX”一词都不会被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。',无论您尝试使用何种命令,无论操作系统版本如何,通常都会出现安装/配置问题。


推荐阅读