How to get the usage for an storage account in Microsoft azure using powershell.
I am able to get the storage accounts present in an subscription. But these variables are not exposing any methods by which i can get the usage of an storage account.
How to get the usage for an storage account in Microsoft azure using powershell.
I am able to get the storage accounts present in an subscription. But these variables are not exposing any methods by which i can get the usage of an storage account.
I'd say the easiest way (afaik) would be to enable Storage analytics metrics on the storage account and then fetch and aggregate on the logs.
Example (enable metric on Blob)
Set-StorageServicePropertiesForAnalytics -ServiceName "Blob" -StorageAccountName "<Storage Account Name>" -StorageAccountKey "<Storage Account Key>" -MetricsEnabled -MetricsRetentionPolicyDays 7 -MetricsRetentionPolicyEnabled
NB: You have to wait for a while (a day) after enabling the log
Then aggregate (and fetch the usage on the storage account after a day or so):
$logName = "C:\tmp\StorageAccount.log";
Get-StorageAnalyticsMetrics -DataType "Capacity" -ServiceName "Blob" -LocalPath $logName -StorageAccountName "<StoragE account name"> -StorageAccountKey "<Storage account key>"
$results = (Import-Csv $logName | Where-Object { $_.Category -eq "data" } | Select-Object -Last 1 @{Name="AccountName";Expression={"My storage account"}}, Time, "Capacity (bytes)", "Container count", "Object count")
$results
Should give you a data set which is easy to display and aggregate on. You could also iterate multiple storage accounts / containers and split this if you want. This example only fetches for the blob service. You can also get storage analytics used for other services (table/queue etc); however as specified in the documentation the capacity metric is only available for the blob storage.
For more information on storage account analytics and options see here:
http://msdn.microsoft.com/en-us/library/windowsazure/hh343258.aspx
Please note that after enabling the analytics on the Storage account, you'll have to wait before exporting the logs and aggregating on the data.