@Girish Prajwal Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
To determine the total size allocated to a storage account and the consumed size for each of its storage types (queues, tables, blobs, and files), you can use either PowerShell or Kusto Query Language (KQL).
Calculate the size/capacity of storage account and it services (Blob/Table)
Using PowerShell, you can use the Get-AzMetric
cmdlet to retrieve the total size allocated to a storage account, and the Get-AzStorageAccountUsage
cmdlet to retrieve the consumed size for each storage type. Here's an example PowerShell script to achieve this:
# Login to your Azure account
Connect-AzAccount
# Set the context to the subscription that contains your storage account
Set-AzContext -SubscriptionId <SubscriptionId>
# Retrieve the total allocated size of the storage account
$storageAccountName = "<StorageAccountName>"
$resourceId = "/subscriptions/<SubscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.Storage/storageAccounts/$storageAccountName"
$metric = Get-AzMetric -ResourceId $resourceId -TimeGrain PT1H -MetricName BlobCapacity -AggregationType Total -StartDate (Get-Date).AddDays(-1) -EndTime (Get-Date)
$totalSize = $metric.Data | Select-Object -ExpandProperty Total | Select-Object -First 1
# Retrieve the consumed size for each storage type
$usage = Get-AzStorageAccountUsage -ResourceGroupName <ResourceGroupName> -Name $storageAccountName
$blobSize = $usage | Where-Object {$_.Name.Value -eq "BlobCapacity"} | Select-Object -ExpandProperty CurrentValue
$tableSize = $usage | Where-Object {$_.Name.Value -eq "TableCapacity"} | Select-Object -ExpandProperty CurrentValue
$queueSize = $usage | Where-Object {$_.Name.Value -eq "QueueCapacity"} | Select-Object -ExpandProperty CurrentValue
$fileSize = $usage | Where-Object {$_.Name.Value -eq "FileCapacity"} | Select-Object -ExpandProperty CurrentValue
# Print the results
Write-Host "Total allocated size: $totalSize bytes"
Write-Host "Blob consumed size: $blobSize bytes"
Write-Host "Table consumed size: $tableSize bytes"
Write-Host "Queue consumed size: $queueSize bytes"
Write-Host "File consumed size: $fileSize bytes"
Using KQL, you can use the AzureStorageCapacity
table to retrieve the total allocated size of the storage account, and the AzureStorageUsage
table to retrieve the consumed size for each storage type. Here's an example KQL query to achieve this:
AzureStorageCapacity
| where ResourceId contains "/providers/Microsoft.Storage/storageAccounts/"
| where ResourceId contains "<StorageAccountName>"
| summarize TotalAllocatedSize = sum(TotalCapacity) by StorageType
| join (
AzureStorageUsage
| where ResourceId contains "/providers/Microsoft.Storage/storageAccounts/"
| where ResourceId contains "<StorageAccountName>"
| summarize CurrentUsage = sum(CurrentValue) by StorageType
) on StorageType
| project StorageType, TotalAllocatedSize, CurrentUsage
This query retrieves the total allocated size and current usage for each storage type, and displays the results in a table. You can run this query in Azure Monitor Logs or Azure Data Explorer to retrieve the information for all storage accounts across your subscriptions.
Please let us know if you have any further queries. I’m happy to assist you further.
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.