Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. # this script will show how to get the total size of the blobs in a container
  2. # before running this, you need to create a storage account, create a container,
  3. # and upload some blobs into the container
  4. # note: this retrieves all of the blobs in the container in one command.
  5. # if you are going to run this against a container with a lot of blobs
  6. # (more than a couple hundred), use continuation tokens to retrieve
  7. # the list of blobs.
  8.  
  9. # these are for the storage account to be used
  10. $resourceGroup = ""
  11. $storageAccountName = ""
  12. $containerName = ""
  13.  
  14. # get a reference to the storage account and the context
  15. $storageAccount = Get-AzStorageAccount `
  16. -ResourceGroupName $resourceGroup `
  17. -Name $storageAccountName
  18. $ctx = $storageAccount.Context
  19.  
  20. # get a list of all of the blobs in the container
  21. $listOfBLobs = Get-AzStorageBlob -Container $ContainerName -Context $ctx
  22.  
  23. # zero out our total
  24. $length = 0
  25.  
  26. # this loops through the list of blobs and retrieves the length for each blob
  27. # and adds it to the total
  28. $listOfBlobs | ForEach-Object {$length = $length + $_.Length}
  29.  
  30. # output the blobs and their sizes and the total
  31. Write-Host "List of Blobs and their size (length)"
  32. Write-Host " "
  33. $listOfBlobs | select Name, Length
  34. Write-Host " "
  35. Write-Host "Total Length = " $length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement