Created
September 26, 2023 20:23
-
-
Save HiteaFR/901b9bc471b75d6df304b77da0be3417 to your computer and use it in GitHub Desktop.
Calculer la taille totale d’un conteneur de stockage Azure
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
# 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