Azure Container Sizes

Richard Garel-Jones 0 Reputation points


I have 3 Azure storage accounts with a total of 150 containers. Is there a way I can get a csv export of the total size of each container rather than having to go into each container individually?

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,293 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Azar 3,155 Reputation points

    Hi @Richard Garel-Jones

    Yes, you can get a CSV export of the total size of each container in your Azure storage accounts without having to go into each container individually. You can use Azure PowerShell or Azure CLI to automate this task.

    I'll give you sample commands below for powershell and also Azure CLI, use whichever is comfortable.

    # Login to your Azure account
    # Specify your Azure storage account names
    $storageAccountNames = "storageAccount1", "storageAccount2", "storageAccount3"
    # Initialize an array to store the results
    $containerSizes = @()
    # Loop through the storage accounts
    foreach ($storageAccountName in $storageAccountNames) {
        $containers = Get-AzStorageContainer -Context (Get-AzStorageAccount -ResourceGroupName <YourResourceGroupName> -Name $storageAccountName).Context
        foreach ($container in $containers) {
            $containerSize = Get-AzStorageContainerStatistics -Context $container.Context
            $containerInfo = [PSCustomObject]@{
                StorageAccountName = $storageAccountName
                ContainerName = $container.Name
                TotalSizeInBytes = $containerSize.TotalSize
            $containerSizes += $containerInfo
    # Export the results to a CSV file
    $containerSizes | Export-Csv -Path "container_sizes.csv" -NoTypeInformation
    # Log in to your Azure account
    az login
    # Set your Azure subscription
    az account set --subscription "<put YourSubscriptionName>"
    # Specify your Azure storage account names
    storageAccountNames=("storageAccount1" "storageAccount2" "storageAccount3")
    # Initialize an array to store the results
    # Loop through the storage accounts
    for storageAccountName in "${storageAccountNames[@]}"; do
        containers=$(az storage container list --account-name "$storageAccountName" --query "[].name" --output tsv)
        for container in $containers; do
            containerSize=$(az storage container show --name "$container" --account-name "$storageAccountName" --query "properties | {Name: name, TotalSize: properties | {TotalSize: properties.metadata.TotalSize}}" --output json)
    # Export the results to a CSV file
    echo "StorageAccountName,ContainerName,TotalSizeInBytes" > container_sizes.csv
    for size in "${containerSizes[@]}"; do
        echo "$size" >> container_sizes.csv

    If you find this answer useful kindly accept it, thanks very much.

    0 comments No comments

  2. Ramya Harinarthini_MSFT 4,706 Reputation points Microsoft Employee

    @Richard Garel-Jones

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    You can calculate the size of a Blob storage container – via Blob Inventory

    Step 1: - Enable Inventory Report

    1. Sign in to the Azure portal to get started.
    2. Locate your storage account and display the account overview.
    3. Under Data management, select Blob inventory.
    4. Select Add your first inventory rule.User's image

    The Add a rule page appears.

    1. In the Add a rule page, name your new rule.
    2. Choose a container.
    3. Under Object type to inventory, choose whether to create a report for blobs.

    If you select Blob, then under Blob subtype, choose the types of blobs that you want to include in your report, and whether to include blob versions and/or snapshots in your inventory report

    8.Select the fields that you would like to include in your report and the   format of your reports. Please make sure to include Content-Length from the fields.
    1. Choose how often you want to generate reports.
    2. Optionally, add a prefix match to filter blobs in your inventory report.

     11. Select Save.

    Inventory output

    Each inventory rule generates a set of files in the specified inventory destination container for that rule. The inventory output is generated under the following path:   https://<accountName><inventory-destination-container>/YYYY/MM/DD/HH-MM-SS/<r... where:

    • accountName is your Azure Blob Storage account name.
    • inventory-destination-container is the destination container you specified in the inventory rule.
    • YYYY/MM/DD/HH-MM-SS is the time when the inventory began to run.
    • ruleName is the inventory rule name.

    ![thumbnail image 1 of blog post titled

    						Calculating Container Level Stats in Azure Blob Storage


    Source Link:

    Hope this helps!
    Kindly let us know if the above helps or you need further assistance on this issue.

    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.