You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AzureFileCopy@5报错:'Get-AzResource' cmdlet未识别,求技术支持

问题描述

我正尝试创建一条将GitHub仓库文件推送到Azure Blob存储的流水线。此前已解决Az.Accounts模块未找到的问题(该模块已安装在VM中),按照建议卸载VM上的AzureRM以解决AzureRM与Az模块冲突后,目前遇到新报错,流水线输出如下:

Starting: AzureFileCopy
Task : Azure file copy
Description : Copy files to Azure Blob Storage or virtual machines
Version : 5.210.1
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-file-copy
Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\1.7.0\Az.Accounts.psd1 -Global
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount -ServicePrincipal -Tenant xx-xx-xx-xx-xx -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
Set-AzContext -SubscriptionId xxxxxx-xxx-xxx-xxx-xxxxxx -TenantId xxx-xxx-xx-xx
Disconnect-AzAccount -Scope Process -ErrorAction Stop
Clear-AzContext -Scope Process -ErrorAction Stop
##[error]The term 'Get-AzResource' 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.
Finishing: AzureFileCopy

解决方案
  • 安装Az.Resources模块:Get-AzResource属于Az.Resources模块,当前流水线仅导入了Az.Accounts,需在VM上安装该模块,执行命令:
    Install-Module -Name Az.Resources -Force -AllowClobber
    
  • 安装完整Az模块套件:AzureFileCopy任务依赖多个Az模块组件,直接安装完整Az模块可避免单个模块缺失问题,执行命令:
    Install-Module -Name Az -Force -AllowClobber
    
  • 更新Az模块到兼容版本:当前使用的Az.Accounts 1.7.0版本较旧,可能与其他模块存在兼容性问题,更新所有Az模块到最新版本:
    Update-Module -Name Az -Force
    
  • 确保任务执行前导入Az.Resources:在流水线的AzureFileCopy任务前添加PowerShell步骤,显式导入Az.Resources模块:
    Import-Module Az.Resources -Global
    

内容的提问来源于stack exchange,提问作者khmub

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 23:46:00