Skip to content

Instantly share code, notes, and snippets.

@mattruma
Last active January 22, 2021 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattruma/fcb1c190be478df25fe9ebf4b76aa7b1 to your computer and use it in GitHub Desktop.
Save mattruma/fcb1c190be478df25fe9ebf4b76aa7b1 to your computer and use it in GitHub Desktop.
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