Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all Azure Resources without tags in a Azure Resource Group

In my Azure dev/test lab (DTL), there are many resources which were not tagged. How can I get a list of all untagged resources under DTL/resource group?

like image 595
DevX Avatar asked Sep 14 '17 16:09

DevX


People also ask

Do Azure resources inherit tags from resource groups?

Resources don't inherit the tags you apply to a resource group or a subscription. To apply tags from a subscription or resource group to the resources, see Azure Policies - tags.

How do I get a list of resources in Azure?

In case you need to get a list of resources you have created in Microsoft Azure, use Get-AzureRMResource PowerShell cmdlet. Above command exports all Azure Resources in a CSV named AllAzureRes. CSV. The CSV file also contains the Resource Group name for each resource.

What is the quickest way to find resources in Azure?

To quickly access Azure resources, we leverage search functionality available in the Azure Portal. You can just type the resources name to appear on the list and then you can access azure resources from there. The search list by default shows the recently use Azure resources for quick access.

How do you add a tag to all resources in the resource group?

From the Azure Portal, navigate to All Resources. From there select all the resource checkboxes for which you want to assign a common tag. Then just click on Assign Tags. It will bring up the Assign Tags blade, where you can just need to provide the tags name and value.


1 Answers

Here's a simple PowerShell loop to get untagged resources.

$resources = Get-AzureRmResource
foreach($resource in $resources)
{
    if ($resource.Tags -eq $null)
    {
        echo $resource.Name, $resource.ResourceType
    }
}

Other ways to query this information and also set tags programmatically or as part of resource deployments are described here.

If you want to avoid the situation of ending up with untagged resources, you could enforce a customized policy that all resources should have a value for a particular tag.

like image 81
huysmania Avatar answered Oct 17 '22 19:10

huysmania