Unable to delete multiple (1000+)storage containers using powershell scripts

Sneha VK 0 Reputation points
2023-05-09T13:10:08.43+00:00

Unable to delete multiple containers (1000+)within storage accounts at a time using powershell. When i run the pipeline It is able to display the correct number of containers to be deleted but it is not deleting all the container it displayed to be deleted. Please let me know if there is any limit set for the deletion of storage containers at a time using powershell.

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,913 questions
{count} votes

1 answer

Sort by: Most helpful
  1. dashanan13 930 Reputation points
    2023-05-10T14:26:35.9066667+00:00

    Hei @Sneha VK ,

    Thank you for reaching out to Microsoft Q and A

    The most probable reason for you to be able to see the containers even after you deleted it is because the storage account may have soft delete setting enabled.

    You can read about it here

    This setting essentially is to avoid accidents, when you delete a container and want it back. This is the reason when the storage account is queried for containers it results in a field called "Isdeleted". This setting is under Data management > Data protection, in the storage account menu. I would not recommend removing the retention period in the setting, it is a fail safe.

    Another reason can be that the container blob are being leased, it may help to check enumerate each blob in each container, check the lease state, update it to 'available' if it is leased (if business approves) and then try to delete the container.

    you can check the leased state of a blob via this command line, it is easy to put it in loop to check multiple conainer blobs.

    $mysa = Get-AzStorageAccount -ResourceGroupName mohit-temperory -Name qwertymnbvcxz $mycontainer = Get-AzStorageContainer -Context $mysa.Context -Name deleteme (Get-AzStorageBlob -Container $mycontainer.Name -Context $mysa.Context).BlobClient.GetProperties().Value.LeaseState

    Please "Mark as answer" if it helped.