0

How to calculate size of all Azure Storage Tables from a Subscription using Powershell.

I tried to search online if there is any direct way of querying table sizes but looks like there isn't. Can you someone please give me a working model of calculating a Azure Storage Table size.

Please.

FOREACH ($SubscriptionID in $Subscriptions) { 
    Write-Host -ForegroundColor Green "Working on $N. $SubscriptionID" 

    $StorageAccounts = Get-AzStorageAccount
    FOREACH ($StorageAccount in $StorageAccounts) {
            $StorageAccountName = $StorageAccount.StorageAccountName
            Write-Host -ForegroundColor Yellow "Working on $StorageAccountName"

            $AllTables = Get-AzStorageTable -Context $StorageAccount.Context
            FOREACH ($TableName in $AllTables) {
                
                $Name = $TableName.Name
                Write-Host -ForegroundColor Green "Working on $StorageAccountName,$Name"
                Get-AzStorageTable –Name $TableName.Name –Context $StorageAccount.Context
                
                }             
            }
            $N = $N+1
    }
Joy Wang
  • 39,905
  • 3
  • 30
  • 54
Vinny
  • 461
  • 1
  • 5
  • 18

1 Answers1

1

You can calculate the size of all Azure Storage Tables, but the minimum granularity could just be all the tables in a storage account, not a specific table.

Try the command as below, it works fine on my side.

$StorageAccounts = Get-AzStorageAccount
foreach($item in $StorageAccounts){
    $id = $item.Id+"/tableServices/default"
    $name = $item.StorageAccountName
    $metric = Get-AzMetric -ResourceId $id -MetricName "TableCapacity" -WarningAction Ignore
    $data = $metric.Data.Average/1024/1024
    Write-Output "Tables in $name : $data MB"
}

enter image description here


Besides, looks you want to use the command in several subscriptions, if so, I think you need to run Set-AzContext to set the subscription before running the command above.

Set-AzContext -SubscriptionId "xxxx-xxxx-xxxx-xxxx"
Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • You are the best. It worked like a charm. I'll now start working on piping the result Subscription and Per Storage Account into our SQL DB. – Vinny Nov 01 '19 at 17:37