I'm using the AZ metrics command found in the answer posted below which usually works but every so often the result returns 0, even though I know the account is consuming storage. Also, if I run the same command against the same resource a little while later it returns the real result. Is anyone else using this method and finding similar results? Any suggestions to get around this?
Also, is it possible to use timegrain/timespan against a Storage Account?
List used space for blobs, files, tables, queues using PowerShell?
For reference, the command I'm using is: (Get-AzMetric -ResourceId "{resource_id}" -MetricName "UsedCapacity").Data
I tried to reproduce the same in my environment and faced the same issue.
When I ran the command again after some time, got null value like below:
After a while, when I ran the above command again, it gave the response successfully.
This issue usually happens because capacity metrics values will be refreshed daily (up to 24 Hours).
$DebugPreference = "Continue"
.As a workaround, you can make use of timegrain/timespan against the storage account like below:
(Get-AzMetric -ResourceId "your_resource_id" -MetricName "UsedCapacity" -AggregationType Average -StartTime "02:00:00" -EndTime "04:00:00").Data
If still the issue persists, raise a bug/Azure support ticket.
References:
0-Value Result Get-AzMetric (UsedCapacity) · Issue #15863 · Azure/azure-powershell · GitHub