-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathCalculate_the_size_blob_container.ps1
46 lines (34 loc) · 1.38 KB
/
Calculate_the_size_blob_container.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Set-Location c:\
Clear-Host
Install-Module -Name Az -Force -AllowClobber -Verbose
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
# 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
# these are for the storage account to be used
$resourceGroup = "tw-rg100"
$storageAccountName = "twstacc2020"
$containerName = "testblobs"
# 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
#Clean Up
Remove-AzResourceGroup -Name $resourceGroup -Force