This code snippet allows the recursive tagging of Azure objects within a Resource Group with a predefines set of values
Get-AzureRmSubscription –SubscriptionName “MY AZURE SUBSCRIPTION” | Select-AzureRmSubscription
$allobjects =Get-AzureRmResource
$ResourceGroupName = 'EXAMPLE-RESOURCEGROUP'
#Set TAGS
$myTags = New-Object System.Collections.Hashtable;
$myTags.Add("OperationalSupportTeam","techsupport@laurierhodes.info")
$myTags.Add("Environment","Production")
$myTags.Add("Expiration Date","01/01/2030")
$myTags.Add("Owner","laurie@laurierhodes.info")
#Set Tags on Resource Group
$resgroup = Get-AzureRmResourceGroup -Name $ResourceGroupName
Set-AzureRmResource -Tag $myTags -ResourceId $resgroup.ResourceId -force
#Tag all elements of the Resource Group
ForEach ($armobject In $allobjects) {
if($armobject.ResourceGroupName -eq $ResourceGroupName){
Set-AzureRmResource -Tag $myTags -ResourceId $armobject.ResourceId -force
}
}
- Log in to post comments