Skip to content

Commit cf75455

Browse files
Manjunath-microsoftsihegde
authored andcommitted
Create PS_IdentifyTheEmptyContainersInTheStorageAccount.ps1
1 parent 6413392 commit cf75455

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#The below PowerShell script helps to identify the empty containers in the storage account.
2+
3+
###ATTENTION: DISCLAIMER###
4+
5+
#DISCLAIMER
6+
#The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, owners of this repository or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including,
7+
#without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
8+
9+
10+
############# Script Overview #################################################################
11+
12+
########## Helps to identify the empty containers in the storage account #########
13+
14+
# Ensure you have the Azure PowerShell module installed
15+
# Install-Module -Name Az -AllowClobber -Force
16+
17+
# Import the Azure module if not already
18+
#Import-Module Az
19+
20+
# Connect to your Azure account
21+
Connect-AzAccount
22+
23+
# Define the storage account details
24+
$resourceGroupName = "ResourceGroupName"
25+
$storageAccountName = "StorageaccountName"
26+
27+
# Get the storage account context
28+
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
29+
$ctx = $storageAccount.Context
30+
31+
# List all containers in the storage account
32+
$containers = Get-AzStorageContainer -Context $ctx
33+
34+
# Iterate through each container and check if it is empty
35+
foreach ($container in $containers) {
36+
$blobList = Get-AzStorageBlob -Container $container.Name -Context $ctx
37+
if ($blobList.Count -eq 0) {
38+
Write-Output "Empty container found: $($container.Name)"
39+
}
40+
}
41+
42+
## Disconnect from Azure Account
43+
Disconnect-AzAccount

0 commit comments

Comments
 (0)