Skip to content

Commit d0085a7

Browse files
Merge pull request #259700 from normesta/normesta-reg-updates-12
Replacing inline script with a link
2 parents 6a43dd4 + ed94229 commit d0085a7

File tree

1 file changed

+2
-108
lines changed

1 file changed

+2
-108
lines changed

articles/storage/scripts/storage-blobs-container-calculate-size-powershell.md

Lines changed: 2 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ author: normesta
88
ms.service: azure-storage
99
ms.devlang: powershell
1010
ms.topic: sample
11-
ms.date: 11/21/2023
11+
ms.date: 12/04/2023
1212
ms.author: normesta
1313
ms.custom: devx-track-azurepowershell
1414
---
@@ -26,113 +26,7 @@ This script calculates the size of all Azure Blob Storage containers in a storag
2626
2727
## Sample script
2828

29-
```powershell
30-
# This script will show how to get the total size of the blobs in all containers in a storage account.
31-
# Before running this, you need to create a storage account, at least one container,
32-
# and upload some blobs into that container.
33-
# note: this retrieves all of the blobs in each container in one command.
34-
# Run the Connect-AzAccount cmdlet to connect to Azure.
35-
# Requests that are sent as part of this tool will incur transactional costs.
36-
#
37-
38-
$containerstats = @()
39-
40-
# Provide the name of your storage account and resource group
41-
$storage_account_name = "<name-of-your-storage-account>"
42-
$resource_group = "<name-of-your-resource-group"
43-
44-
# Get a reference to the storage account and the context.
45-
$storageAccount = Get-AzStorageAccount `
46-
-ResourceGroupName $resource_group `
47-
-Name $storage_account_name
48-
$Ctx = $storageAccount.Context
49-
50-
$container_continuation_token = $null
51-
do {
52-
$containers = Get-AzStorageContainer -Context $Ctx -MaxCount 5000 -ContinuationToken $container_continuation_token
53-
$container_continuation_token = $null;
54-
55-
if ($containers -ne $null)
56-
{
57-
$container_continuation_token = $containers[$containers.Count - 1].ContinuationToken
58-
59-
for ([int] $c = 0; $c -lt $containers.Count; $c++)
60-
{
61-
$container = $containers[$c].Name
62-
Write-Verbose "Processing container : $container"
63-
$total_usage = 0
64-
$total_blob_count = 0
65-
$soft_delete_usage = 0
66-
$soft_delete_count = 0
67-
$version_usage = 0
68-
$version_count =
69-
$snapshot_count = 0
70-
$snapshot_usage = 0
71-
$blob_continuation_token = $null
72-
73-
do {
74-
$blobs = Get-AzStorageBlob -Context $Ctx -IncludeDeleted -IncludeVersion -Container $container -ConcurrentTaskCount 100 -MaxCount 5000 -ContinuationToken $blob_continuation_token
75-
$blob_continuation_token = $null;
76-
77-
if ($blobs -ne $null)
78-
{
79-
$blob_continuation_token = $blobs[$blobs.Count - 1].ContinuationToken
80-
81-
for ([int] $b = 0; $b -lt $blobs.Count; $b++)
82-
{
83-
$total_blob_count++
84-
$total_usage += $blobs[$b].Length
85-
86-
if ($blobs[$b].IsDeleted)
87-
{
88-
$soft_delete_count++
89-
$soft_delete_usage += $blobs[$b].Length
90-
}
91-
92-
if ($blobs[$b].SnapshotTime -ne $null)
93-
{
94-
$snapshot_count++
95-
$snapshot_usage+= $blobs[$b].Length
96-
}
97-
98-
if ($blobs[$b].VersionId -ne $null)
99-
{
100-
$version_count++
101-
$version_usage += $blobs[$b].Length
102-
}
103-
}
104-
105-
If ($blob_continuation_token -ne $null)
106-
{
107-
Write-Verbose "Blob listing continuation token = {0}".Replace("{0}",$blob_continuation_token.NextMarker)
108-
}
109-
}
110-
} while ($blob_continuation_token -ne $null)
111-
112-
Write-Verbose "Calculated size of $container = $total_usage with soft_delete usage of $soft_delete_usage"
113-
$containerstats += [PSCustomObject] @{
114-
Name = $container
115-
TotalBlobCount = $total_blob_count
116-
TotalBlobUsageinGB = $total_usage/1GB
117-
SoftDeletedBlobCount = $soft_delete_count
118-
SoftDeletedBlobUsageinGB = $soft_delete_usage/1GB
119-
SnapshotCount = $snapshot_count
120-
SnapshotUsageinGB = $snapshot_usage/1GB
121-
VersionCount = $version_count
122-
VersionUsageinGB = $version_usage/1GB
123-
}
124-
}
125-
}
126-
127-
If ($container_continuation_token -ne $null)
128-
{
129-
Write-Verbose "Container listing continuation token = {0}".Replace("{0}",$container_continuation_token.NextMarker)
130-
}
131-
} while ($container_continuation_token -ne $null)
132-
133-
Write-Host "Total container stats"
134-
$containerstats | Format-Table -AutoSize
135-
```
29+
:::code language="azurepowershell" source="~/azure_powershell_scripts/storage/calculate-container-size/calculate-container-sizes-in-account.ps1":::
13630

13731
## Clean up deployment
13832

0 commit comments

Comments
 (0)