Skip to content

Instantly share code, notes, and snippets.

@HiteaFR
Created September 26, 2023 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HiteaFR/901b9bc471b75d6df304b77da0be3417 to your computer and use it in GitHub Desktop.
Save HiteaFR/901b9bc471b75d6df304b77da0be3417 to your computer and use it in GitHub Desktop.
Calculer la taille totale d’un conteneur de stockage Azure
# this script will show how to get the total size of the blobs in a container
# before running this, you need to create a storage account, create a container,
# and upload some blobs into the container
# note: this retrieves all of the blobs in the container in one command.
# if you are going to run this against a container with a lot of blobs
# (more than a couple hundred), use continuation tokens to retrieve
# the list of blobs.
# these are for the storage account to be used
$resourceGroup = ""
$storageAccountName = ""
$containerName = ""
# get a reference to the storage account and the context
$storageAccount = Get-AzStorageAccount `
-ResourceGroupName $resourceGroup `
-Name $storageAccountName
$ctx = $storageAccount.Context
# get a list of all of the blobs in the container
$listOfBLobs = Get-AzStorageBlob -Container $ContainerName -Context $ctx
# zero out our total
$length = 0
# this loops through the list of blobs and retrieves the length for each blob
# and adds it to the total
$listOfBlobs | ForEach-Object {$length = $length + $_.Length}
# output the blobs and their sizes and the total
Write-Host "List of Blobs and their size (length)"
Write-Host " "
$listOfBlobs | select Name, Length
Write-Host " "
Write-Host "Total Length = " $length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment