Skip to content

Instantly share code, notes, and snippets.

@vukasinterzic
Last active January 14, 2022 22:47
Show Gist options
  • Save vukasinterzic/1ba6d75c43a2b8d9d271c50b4e44ef92 to your computer and use it in GitHub Desktop.
Save vukasinterzic/1ba6d75c43a2b8d9d271c50b4e44ef92 to your computer and use it in GitHub Desktop.
Replace Azure Tag Value, keep the Tag Name
#Task 1: Replace Tag Value, keep Tag Name:
# Get all Az Subscriptions
$Subscriptions = Get-AzSubscription
$TagName = 'YourTagName'
$WrongValue = 'wrong tag value'
$CorrectValue = 'new tag value'
$WrongTag = @{$TagName=$WrongValue}
$NewTag = @{$TagName=$CorrectValue}
#subscription loop
foreach ($subscription in $Subscriptions) {
$Resources = @()
Write-Host "Selecting Subscription $($Subscription.Name)... "
Get-AzSubscription -SubscriptionName $Subscription.Name | Set-AZContext
$Resources = Get-AzResource -Tag $WrongTag
foreach ($Resource in $Resources) {
Write-Host "Processing resource $($Resource.Name) ..."
Update-AzTag -ResourceId $Resource.ResourceId -Tag $NewTag -Operation Merge
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment