Skip to content

Instantly share code, notes, and snippets.

@mattruma

mattruma/AddOrUpdateResourceTags.ps1 Secret

Last active Jan 22, 2021
Embed
What would you like to do?
PowerShellScripts
param(
[Parameter(Mandatory = $true)]
[String] $ResourceGroupName,
[Parameter(Mandatory = $true)]
[String] $ResourceName,
[Parameter(Mandatory = $true)]
[Hashtable] $Tags
)
$ErrorActionPreference = "Stop"
$Resource = Get-AzResource -ResourceGroupName $ResourceGroupName -Name $ResourceName
ForEach ($Tag In $Resource.Tags.GetEnumerator()) {
If (!$Tags.ContainsKey($Tag.Key)) {
$Tags.Add($Tag.Key, $Tag.Value)
}
}
ForEach ($Tag In $Tags.GetEnumerator()) {
Write-Host $Tag.Key = $Tag.Value
}
Set-AzResource -ResourceId $Resource.Id -Tag $Tags -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment