0
votes

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.

1
By usage do you mean total size of the storage account or something else?Gaurav Mantri
By usage i mean, the Total usage of the storage accountVenkatakrishnan
Can you please be more specific? Usage could mean different things. It could mean how much data is stored in a storage account or it could also mean how much data stored in that storage account is actually used (we could have blobs in a storage account that are never used). The answer would depend on what kind of usage statistics you're looking for. Thanks.Gaurav Mantri
I need to know how much data is stored in the storage account.Venkatakrishnan

1 Answers

0
votes

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.