build20AcceleratedSpark/tools/compute_data_size.ps1

38 строки
1.4 KiB
PowerShell

# 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
Connect-AzAccount
$resourceGroup = "PipeDream"
$storageAccountName = "pipedreamtaxi1"
$containerName = "yellow"
# 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 / 1024 / 1024 / 1024).ToString('N0')