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

获取指定Azure管理组ABC内资源组遇PowerShell模块错误求解决

解决Azure管理组资源组查询的PowerShell错误问题

问题背景

执行Get-AzResourceGroup查询名为“ABC”的管理组下所有资源组时,触发以下错误:

ERROR:
Get-AzSubscription : Method 'get_SerializationSettings' in type 'Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient' from assembly 'Microsoft.Azure.PowerShell.Clients.ResourceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation. At line:1 char:1

当前环境:Az.Accounts 2.13.0(已尝试降级至2.12.1无效)、Az.Resources 6.10.0。

可行解决方案

方案1:重装兼容的Az模块版本

该错误源于模块版本不兼容,可彻底清理现有模块后安装经过验证的兼容组合:

# 以管理员权限运行PowerShell,卸载所有Az模块
Get-Module -ListAvailable Az.* | Uninstall-Module -Force -AllVersions

# 安装兼容版本的核心模块
Install-Module -Name Az.Accounts -RequiredVersion 2.12.0 -Force -AllowClobber
Install-Module -Name Az.Resources -RequiredVersion 6.9.0 -Force -AllowClobber

方案2:绕过模块冲突的查询脚本

如果重装模块仍有问题,可改用“先获取管理组订阅,再逐个查询资源组”的逻辑:

# 登录Azure(首次运行需执行)
Connect-AzAccount

# 目标管理组名称
$targetMgmtGroup = "ABC"

# 获取管理组下所有订阅ID
$subsInMgmtGroup = Get-AzManagementGroup -GroupName $targetMgmtGroup -Expand -Recurse | 
    Select-Object -ExpandProperty Children | 
    Where-Object Type -eq "/subscriptions" | 
    Select-Object -ExpandProperty Name

# 遍历订阅收集资源组
$allResourceGroups = @()
foreach ($subId in $subsInMgmtGroup) {
    # 切换订阅上下文
    Set-AzContext -Subscription $subId | Out-Null
    # 获取当前订阅下的资源组
    $currentRgs = Get-AzResourceGroup | Select-Object ResourceGroupName, Location, SubscriptionId
    $allResourceGroups += $currentRgs
}

# 输出结果
$allResourceGroups

额外排查建议

  • 升级PowerShell至7.x版本(相比5.1,对Az模块兼容性更好)
  • 若允许全模块更新,执行Update-Module -Name Az -Force升级所有Az模块到最新兼容版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 05:32:22