Azure Tags

Om Bhosle 80 Reputation points
2025-02-14T17:27:55.99+00:00

Hello All,

I have many subscriptions in my azure tenant. And I have assigned multiple tags to multiple resources and resource. So Know I want to download the list of the tags that are assigned and their respective data. It is a bit urgent. If anyone could help me how can I download all the tags that are created in my whole tenant with multiple subscriptions will be really helpful.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,311 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Naveena Patlolla 400 Reputation points Microsoft Vendor
    2025-02-18T06:11:44.0233333+00:00

    Hi Om Bhosle

    Thank you for your response

    I have developed the script to fetch the tags of all resources in all the subscriptions

    Please see the below output below for referenceimage.png

    # Connect to Azure account
    # This command prompts the user to authenticate with their Azure account
    # Connect-AzAccount
    # Initialize an array to store resource tag information
    $allTags = @()
    # Retrieve all Azure subscriptions associated with the account
    $subscriptions = Get-AzSubscription
    # Loop through each subscription
    foreach ($sub in $subscriptions) {
        # Set the context to the current subscription
        Set-AzContext -SubscriptionId $sub.Id
        # Retrieve all resources in the current subscription
        $resources = Get-AzResource
        # Loop through each resource
        foreach ($resource in $resources) {
            # Check if the resource has associated tags
            if ($resource.Tags) {
                # Iterate through each tag key-value pair
                foreach ($tag in $resource.Tags.GetEnumerator()) {
                    # Store tag information along with resource details
                    $allTags += [PSCustomObject]@{
                        SubscriptionName = $sub.Name      # Name of the subscription
                        ResourceName     = $resource.Name  # Name of the resource
                        ResourceType     = $resource.ResourceType  # Type of the resource
                        TagKey           = $tag.Key        # Tag key
                        TagValue         = $tag.Value      # Tag value
                    }
                }
            }
        }
    }
    # Export the collected tag information to a CSV file
    $allTags | Export-Csv -Path ".\resources_tags.csv" -NoTypeInformation
    # Display a message confirming export completion
    Write-Host "Tag information has been exported to resources_tags.csv"
    

    Feel free to reach out if you have any further questions or need additional information—I’m happy to assist!

    Please provide your valuable comments User's image

    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.