Managing cloud costs at scale requires visibility, and that starts with proper resource tagging. Without consistent tags, it becomes nearly impossible to track who owns what, which project a resource belongs to, or how costs should be allocated across departments.
In Azure, tags are key-value pairs attached to resources, resource groups, and subscriptions. A well-designed tagging strategy typically includes at minimum these four tags:
The challenge is that manual tagging does not scale. Resources get created without tags, teams forget to update them, and over time your tagging compliance drifts. PowerShell automation solves this by auditing, enforcing, and reporting on tags programmatically.
The first step is understanding your current state. This script scans all subscriptions and identifies resources missing any of the required tags:
The output is a CSV file you can share with resource owners or import into a tracking system.
Once you know what is missing, the next step is remediation. This script applies default tags to all resources in a resource group, preserving any existing tags:
The merge strategy ensures that existing tags are never overwritten. Default values only fill in gaps.
Finally, measure your progress with a compliance report. This script calculates the percentage of resources that have all required tags:
Run this regularly, or schedule it as an Azure Automation runbook, to track your tagging compliance over time.
PowerShell scripts handle the immediate problem, but for long-term governance, consider combining them with Azure Policy. Tag policies can prevent untagged resources from being created in the first place, while these scripts clean up what already exists.
For more details, see the Azure documentation on tag policies and the governance tutorial for managing tags.