更改预订下所有资源组的标签名称

时间:2020-07-06 16:49:25

标签: azure azure-powershell

我需要更改标签键,但值应保持不变。例如,我有一个名为“ SkuId = 1234”的标签。我需要将键值更改为“ SystemId = 1234”。尝试如下所示。.无效...有任何建议吗?

$resourceGroups = Get-AzResourceGroup
foreach($resourcegroup in $resourceGroups){
$Tags = (Get-AzResourceGroup -Name $resourceGroup).Tags
$Tags += @{"SystemId"=$tags.oldtag}
$Tags.Remove('oldtag')
$resourceGroup.resourcegroupname |Set-AzureRmResourceGroup -Tag $Tags
}

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

$Tags = (Get-AzResourceGroup).Tags
$Tags += @{"SystemId"=$tags.oldtag}
$Tags.Remove('oldtag')
Set-AzureRmResourceGroup -Tag $Tags