Slightly customized PowerShell Script from Microsoft that enumerates all blobs in an Azure blobstorage container and writes out a .csv file to local disk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original script from Microsoft at https://docs.microsoft.com/en-us/azure/storage/scripts/storage-blobs-container-calculate-size-powershell | |
# Login to Azure interactively | |
Login-AzAccount | |
# 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