Azure devops 自托管代理Azure PowerShell(核心)-未找到模块

Azure devops 自托管代理Azure PowerShell(核心)-未找到模块,azure-devops,azure-powershell,azure-devops-self-hosted-agent,Azure Devops,Azure Powershell,Azure Devops Self Hosted Agent,我正在Azure DevOps中运行自托管Windows代理。我已经安装了PowerShell Core 6.2.3,并且作为管理员安装了Az模块,以便所有用户都可以使用 当我使用Azure PowerShell任务(V4)-标记为“使用PowerShell核心”和Azure PowerShell的“最新版本”运行生成时,我收到以下消息: ==============================================================================

我正在Azure DevOps中运行自托管Windows代理。我已经安装了PowerShell Core 6.2.3,并且作为管理员安装了Az模块,以便所有用户都可以使用

当我使用Azure PowerShell任务(V4)-标记为“使用PowerShell核心”和Azure PowerShell的“最新版本”运行生成时,我收到以下消息:

==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 4.159.3
Author       : Microsoft Corporation
Help         : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
Added TLS 1.2 in session.
Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop
##[warning]Run Connect-AzureRmAccount to login.
##[error]Could not find the modules: 'Az.Accounts' with Version: ''. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
如果我在托管代理上运行脚本,它可以正常工作。我不明白为什么它失败了。我假设在构建代理运行的概要文件或环境中会出现一些不同的情况,但我不确定如何检查这一点

在生成代理上,如果我打开PSCore窗口并运行:

Get-Module Az -ListAvailable

它可以正确地找到模块。

DevOps代理很可能以其他用户的身份运行,并且尚未为该用户安装Az模块。假设代理作为服务运行,您可以通过运行
services.msc
检查用户,并查找“Azure管道代理”、“VSTS代理”或“vstsagent.[orgname].[agentname]”[1]

运行
Get Module Az-list available
查看模块的安装位置。已为所有用户安装了
C:\Program Files\PowerShell\Modules
下的模块[2]

您可以通过以下方式为所有用户安装模块:

Install-Module -Name Az -Scope AllUsers
[1]


[2]

您重新启动了机器吗?是的,重新启动了几次!您可以尝试切换到任务的3.0版本,以查看问题是否消失。请参考这个类似的@Hugh V3使用AzureRM,不支持PowerShell核心-我需要这两个!我认为“使用PowerCore核心”复选框没有任何作用(至少在Windows上是这样),它试图使用Windows PowerShell执行它