To check the historical value of an Azure resource tag that was changed 7 days ago, you’ll need to use Azure Activity Logs (since Azure doesn’t natively store tag history). Here’s how:
Method 1: Azure CLI
Query the Activity Log for tag changes on the resource:
az monitor activity-log list \
--resource <RESOURCE_ID> \
--start-time 2023-10-01T00:00:00Z \ # Replace with date 7 days ago
--end-time 2023-10-08T00:00:00Z \
--query "[?operationName.value=='Microsoft.Resources/tags/write']" \
--output jsonc
Key Fields to Check:
Method 2: PowerShell
Use the Get-AzLog cmdlet:
$startTime = (Get-Date).AddDays(-7).ToUniversalTime()
$endTime = Get-Date.ToUniversalTime()
Get-AzLog `
-ResourceId <RESOURCE_ID> `
-StartTime $startTime `
-EndTime $endTime |
Where-Object { $_.OperationName.Value -eq "Microsoft.Resources/tags/write" } |
Select-Object Properties
Parse the Properties field for changes.
Method 3: Azure Portal
- Go to the Azure Monitor blade.
- Navigate to Activity Log.
- Filter by:
- Timespan: Last 7 days
- Resource: Your specific resource
- Operation:
Microsoft.Resources/tags/write
- Check the JSON details of the log entry for
properties.changes.
Method 4: Azure Resource Graph (Advanced)
If you’ve enabled diagnostic settings to send Activity Logs to a Log Analytics workspace:
AzureActivity
| where TimeGenerated > ago(7d)
| where OperationName == "Microsoft.Resources/tags/write"
| where ResourceId == "<RESOURCE_ID>"
| extend Changes = parse_json(Properties).changes
| project Changes
Notes:
- No Native Tag History: Azure doesn’t track tag history by default. This method only works if the tag was modified within the Activity Log retention period (default 90 days).
- Permissions: You need
Reader or Contributor access to the resource or Activity Logs.
- Long-Term Tracking: For future tracking, enable Diagnostic Settings to stream Activity Logs to a Log Analytics workspace or Storage Account.
Let me know if you need help parsing the JSON output!