Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Slightly customized PowerShell Script from Microsoft that enumerates all blobs in an Azure blobstorage container and writes out a .csv file to local disk
# Original script from Microsoft at
# Login to Azure interactively
# Specify the Azure subscription
Select-AzSubscription -SubscriptionName "My Subscription"
$resourceGroup = "my_resourcegroup"
$storageAccountName = "mystorageaccount"
$containerName = "mycontainer"
# Set storage context
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccountName
$ctx = $storageAccount.Context
# Get a list of all of the blobs in the container (millions of blobs means PowerShell memory usage will reach 10s of GB)
# In that case, make sure you do this on an instance with 32 GB or more of memory
$listOfBLobs = Get-AzStorageBlob -Container $ContainerName -Context $ctx
# Zero out our total
$length = 0
# This loops through the list of blobs, retrieves the length for each blob and adds it to the total
$listOfBlobs | ForEach-Object {$length = $length + $_.Length}
Write-Host "Total Length = " $length
# Output the blobs and their sizes and the total
$listOfBlobs | select Name, Length, LastModified, IsDeleted | Export-Csv -Path C:\TEMP\blobs.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment