Delete multiple storage account

Shravya Shanmukha 0 Reputation points
2024-02-22T16:47:40.2333333+00:00
  1. I need to delete unneeded storage accounts. Instead of adding all storage account CLI, is there any way I can delete multiple storage accounts using one CLI?
  2. If I delete the storage account, does containers delete by their own?
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,535 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Amrinder Singh 5,870 Reputation points Microsoft Employee Volunteer Moderator
    2024-02-22T17:12:49.84+00:00

    Hello @Shravya Shanmukha - Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    1. Once you have prepared the list/array of un-used storage accounts, you can pass them in a script and pass the account name list as the parameter to cmdlet for deleting the account.

    2.Yes, once you delete the account, the associated data also gets deleted.

    Kindly let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. KarishmaTiwari-MSFT 20,777 Reputation points Microsoft Employee Moderator
    2024-02-22T17:53:21.3833333+00:00

    @Shravya Shanmukha Thanks for posting your query on Microsoft Q&A.

    #Delete multiple Storage accounts
    1.You can delete multiple storage accounts using their resource IDs using the following command:

    az storage account delete --ids /subscriptions/{SubID}/resourceGroups/{ResourceGroup}/providers/Microsoft.Storage/storageAccounts/{StorageAccount}
    

    --ids

    One or more resource IDs (space-delimited). It should be a complete resource ID containing all information of 'Resource Id' arguments. You should provide either --ids or other 'Resource Id' arguments.

    Documentation: https://learn.microsoft.com/en-us/cli/azure/storage/account?view=azure-cli-latest#az-storage-account-delete

    2.You can also delete multiple storage accounts using this script here: https://learn.microsoft.com/en-us/cli/azure/get-started-tutorial-4-delete-resources?tabs=bash#delete-multiple-azure-resources-using-a-script
    This example in the link gets a list of all the Azure storage accounts in the resource group and deletes them in a for-each loop.

    #Container deletion

    Yes, associated containers/resources in the storage account will also get deleted. When I try to delete the storage account from Azure Portal, it shows that all dependent resources will be deleted, including all the containers.

    User's image


    Hope that helps. If you have questions, please let me know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.

    Please don’t forget to Accept Answer and hit Yes for "was this answer helpful" wherever the information provided helps you, this can be beneficial to other community members for remediation for similar issues.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.