Forum Discussion
Fromelard
Dec 16, 2024Iron Contributor
Powershell Script to remove all Blobs from Storage account
With large number of Blobs in Storage Account, the manual cleanup from the Portal is more complicated and time consuming, as it's per set of 10'000. This script is simple and and can be executed in ...
Fromelard
Dec 16, 2024Iron Contributor
Script updated with the deletion command:
[string]$myConnectionString = "DefaultEndpointsProtocol=https;AccountName=YourStorageAccountName;AccountKey=YourKeyFromStorageAccountConnectionString;EndpointSuffix=core.windows.net"
[string]$ContainerName = "YourBlobContainerName"
[int]$blobCountAfter = 0
[int]$blobCountBefore = 0
$context = New-AzStorageContext -ConnectionString $myConnectionString
$blobCountBefore = (Get-AzStorageBlob -Container $ContainerName -Context $context).Count
Write-Host "Total number of blobs in the container Before deletion: $blobCount" -ForegroundColor Yellow
Get-AzStorageBlob -Container $ContainerName -Context $context | ForEach-Object {
$_ | Remove-AzStorageBlob -ICloudBlob $_.ICloudBlob -Context $context
}
$blobCountAfter = (Get-AzStorageBlob -Container $ContainerName -Context $context).Count
Write-Host "Total number of blobs in the container After deletion : $blobCount" -ForegroundColor Green
It's also possible to add the batch set using the maxcount
Get-AzStorageBlob -Container $ContainerName -Context $context -MaxCount 10000
Fab