使用New-AzManagementGroup创建Azure管理组报错求助
Azure New-AzManagementGroup 类型转换报错解决方案
你遇到的Unable to cast object of type 'Microsoft.Azure.Management.ManagementGroups.Models.ManagementGroup' to type 'Newtonsoft.Json.Linq.JObject'报错是Az.Resources旧版本的已知序列化缺陷,出现在调用New-AzManagementGroup时传递父管理组对象/属性的场景,可通过以下方案解决:
- 方案1:升级Az.Resources模块到最新稳定版
- 以管理员权限启动PowerShell,执行升级命令:
Update-Module -Name Az.Resources -Force -AllowClobber- 重启PowerShell会话,重新登录Azure账号:
Connect-AzAccount- 重新执行原创建命令即可正常运行。
- 方案2:强制转换父ID为纯字符串
如果暂时无法升级模块,可将父ID强制转为字符串类型传递,避开类型识别异常:New-AzManagementGroup -GroupId "MI-Test-testing00" -ParentId "$($parent.Id)" - 方案3:使用Azure CLI作为替代
也可以直接用跨平台的Azure CLI完成管理组创建,不存在PowerShell模块的类型兼容问题:az account management-group create --name MI-Test-testing00 --parent MI-Test
内容的提问来源于stack exchange,提问作者Divyansh Saxena
相关产品推荐
相关产品推荐

