Storage account used capacity showing incorrect in portal compared to actual used capacity

Niket Kumar Singh 435 Reputation points
2023-09-23T16:06:00.16+00:00

I have noticed a significant difference in the reported storage capacity of my Azure Storage Account: Azure Portal used capacity: 4.56 TiB, PowerShell Script: Total Storage Size (Blobs + Files + Queues + Tables) = 0.81754088960588 GB Is there an explanation for this discrepancy? Any insights or guidance on how to reconcile the values would be greatly appreciated.

I have multiple storage accounts on Azure, where 1 of the storage account's total used capacity in Insights is incorrect from actual size.

to check used capacity from portal >> https://techcommunity.microsoft.com/t5/azure-paas-blog/calculate-the-size-capacity-of-storage-account-and-it-services/ba-p/1064046

ms documented sample poweshell script >> [https://learn.microsoft.com/en-us/azure/storage/scripts/storage-blobs-container-calculate-size-powershell#sample-script

My](https://learn.microsoft.com/en-us/azure/storage/scripts/storage-blobs-container-calculate-size-powershell#sample-scriptMy"learn.microsoft.com") modified script >> Document.docx

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.
3,409 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,108 questions
{count} vote

Accepted answer
  1. Ramya Harinarthini_MSFT 5,351 Reputation points Microsoft Employee
    2023-09-27T13:36:39.9566667+00:00


    Niket Kumar Singh

    Thanks for your time over the team's call.

    We have suggested you check the blob capacity through latest version of Azure Storage explorer, and we could see 7 lakhs plus blob count which are in soft deleted state and 400 plus active blobs which is reason why the total capacity was showing 4.35 TB.

    As you wanted to reduce the billing for Azure Storage account, we have suggested you to either delete the soft deleted blobs permanently using the PowerShell script or create a new Storage account and copy all the active blobs to new account and then delete the old one.

    Also, we have shared another recommendation to use blob lifecycle management policy to optimize costs automatically.

    Kindly let us know if the above helped 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.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Niket Kumar Singh 435 Reputation points
    2023-09-24T07:55:27.94+00:00

    Hi @Vinodh247

    thank you for your quick response.

    Again verified the content of the stage account still the used capacity is more than the actual capacity.
    User's image

    soft delete is enabled: still it will not consume that much of space.
    User's image

    coming to the portal the used capacity is:
    User's image

    using powershell below is the output:
    User's image

    below is the script:

    # Function to convert bytes to gigabytes (GB)
    function ConvertTo-GB {
        param (
            [double]$sizeInBytes
        )
    
        return $sizeInBytes / 1GB
    }
    
    # These are for the storage account to be used
    $resourceGroup = "yourrg"
    $storageAccountName = "yourstorageaccountname"
    
    # Initialize the total size in bytes
    $totalSizeInBytes = 0
    
    # Get a reference to the storage account and the context
    $storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
    $ctx = $storageAccount.Context
    
    # Calculate total blob size
    $containers = Get-AzStorageContainer -Context $ctx
    foreach ($container in $containers) {
        $listOfBlobs = Get-AzStorageBlob -Container $container.Name -Context $ctx
        $listOfBlobs | ForEach-Object {
            $blobSizeInBytes = $_.Length
            $totalSizeInBytes += $blobSizeInBytes
        }
    }
    
    # Calculate total file share size
    $fileShares = Get-AzStorageShare -Context $ctx
    foreach ($fileShare in $fileShares) {
        $fileShareProperties = Get-AzStorageShareStats -Share $fileShare.Name -Context $ctx
        $totalSizeInBytes += $fileShareProperties.Usage
    }
    
    # Calculate total queue size
    $queues = Get-AzStorageQueue -Context $ctx
    foreach ($queue in $queues) {
        $queueProperties = Get-AzStorageQueueMetrics -Queue $queue.Name -Context $ctx
        $totalSizeInBytes += $queueProperties.Total
    }
    
    # Calculate total table size
    $tables = Get-AzStorageTable -Context $ctx
    foreach ($table in $tables) {
        $tableProperties = Get-AzStorageTableMetrics -Table $table.Name -Context $ctx
        $totalSizeInBytes += $tableProperties.Total
    }
    
    # Convert the total size to gigabytes (GB)
    $totalSizeInGB = ConvertTo-GB -sizeInBytes $totalSizeInBytes
    
    # Output the total used capacity for the storage account
    Write-Host "Total Used Capacity of Storage Account = $totalSizeInGB GB"
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.