Created
September 4, 2017 11:42
-
-
Save taddison/61246f3b7b8be7722d32a6ea99fc768d to your computer and use it in GitHub Desktop.
Remove a tag (AzureRM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############ | |
# Remove a tag | |
$tagToRemove = "SupportContact" | |
Write-Host [Start] Tag utilisation: $tagToRemove | |
Get-AzureRmTag -Name $tagToRemove | |
## Remove from resources | |
$resources = Find-AzureRmResource -Tag @{$tagToRemove=$null} | |
foreach($resource in $resources) | |
{ | |
$resourceTags = (Get-AzureRmResource -ResourceId $resource.ResourceId).Tags | |
$resourceTags.Remove($tagToRemove) | |
Set-AzureRmResource -Tag $resourceTags -ResourceId $resource.ResourceId -Force | |
} | |
## Remove from resource groups | |
$groups = Find-AzureRmResourceGroup -Tag @{$tagToRemove=$null} | |
foreach($group in $groups) | |
{ | |
$groupTags = (Get-AzureRmResourceGroup -ResourceId $group.ResourceId).Tags | |
if($groupTags -ne $null -and $groupTags.ContainsKey($tagToRemove)) | |
{ | |
$groupTags.Remove($tagToRemove) | |
Set-AzureRmResourceGroup -Tag $groupTags -ResourceId $group.ResourceId | |
} | |
} | |
Write-Host [Done] Tag utilisation: $tagToRemove | |
Get-AzureRmTag -Name $tagToRemove | |
############ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment