What is the easiest way to find the total number of blobs in a container?

David Maryo 116 Reputation points
2024-03-30T18:48:14.16+00:00

I'm seeking guidance on the most efficient method to count the number of blobs within an Azure Storage Container, as well as retrieving the last modified timestamp of the 10 most recent blobs. Unfortunately, it appears that Azure Storage Explorer doesn't currently offer this functionality.

Manually navigating through various directories (<NAME>/YYYY/MM/DD/HH/<filename_001.csv>) to achieve this task is cumbersome and time-consuming.

Does Azure CLI offer a solution to fulfill these requirements? Any assistance on this matter would be greatly appreciated.

Thank you in advance for your help!

Azure Storage Explorer
Azure Storage Explorer
An Azure tool that is used to manage cloud storage resources on Windows, macOS, and Linux.
266 questions
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,225 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Marcin Policht 25,925 Reputation points MVP
    2024-03-30T18:56:37.1433333+00:00

    You can use Azure Storage Explorer:

    Open Azure Storage Explorer and navigate to your storage account.

    Expand the storage account, then navigate to the container for which you want to count the blobs.

    Right-click on the container and select "Properties."

    In the properties window, you should see information about the container, including the number of blobs it contains.

    Alternatively, if you prefer using Azure PowerShell, you can run:

    $context = New-AzStorageContext -StorageAccountName <StorageAccountName> -StorageAccountKey <StorageAccountKey>
    $blobCount = (Get-AzStorageBlob -Container <ContainerName> -Context $context).Count
    Write-Host "Total number of blobs in the container: $blobCount"
    
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    1 person found this answer helpful.

  2. Nehruji R 8,146 Reputation points Microsoft Vendor
    2024-04-01T07:04:58.91+00:00

    Hello David,

    Greetings! Welcome to Microsoft Q&A Platform.

    Apologies for the inconvenience causing. I understand that you encounter discrepancies between Azure Storage Explorer and PowerShell when counting blobs in an Azure Storage container per your latest above comment,

    For general information, some resources are hidden and not included in the normal listing requests. These are usually containers or tables maintained by the platform, such as for logging purposes. Make sure to include any snapshots, versions and soft deleted blobs/versions in your calculation. there might be hidden system containers counted by the metrics API.

    The easiest non programmatic method is to navigate to the folder in Azure Storage Explorer and select folder statistics. This will provide the number of blobs and size. You could also setup Azure Storage blob inventory. Which would allow you Calculate blob count and total size per container.

    Also, it will generate a CSV that you can parse to calculate what you are looking for: Enable Azure Storage blob inventory reports | Microsoft Learn

    Alternatively, you can use the Azure CLI and use the below command. You can use the Cloud Shell User's image

    at the top right of the Azure portal to perform this.

    This will give you a total number of blobs. Also, if you remove the line "-query "length(@)" it will show the actual blob files details.

    This method authenticates using Azure AD, so make sure you have at least the "Storage Blob data reader" role on the storage account, below performing the command.

    az storage blob list -c "your-container-name" --account-key "your-storage-account-key" --account-name "your-storage-account-name" --query "length(@)" -o table

    Can you please cross verify again and let me know the status.

    Similar reference threads - https://stackoverflow.com/questions/6861865/getting-blob-count-in-an-azure-storage-container, https://stackoverflow.com/questions/70569511/how-to-get-the-count-of-containers-in-blob-storage-account-using-azure-data-fact, https://learn.microsoft.com/en-us/answers/questions/1435630/how-to-get-blob-containers-details-from-storage-ac

    Hopefully this helps you.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.

    0 comments No comments

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.