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 reference
# 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
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.