Introduction

In this blog, you will see how to delete a container from an Azure Storage Account using PowerShell.

Prerequisites:

Install Azure PowerShell Module to run the script.

PowerShell Script:

Open Notepad and paste the following script. Save the file as script.ps1.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. $containerName="container003"
  6. ## Connect to Azure Account
  7. Connect-AzAccount
  8. ## Function to delete a container
  9. Function DeleteStorageContainer
  10. {
  11. Write-Host -ForegroundColor Green "Deleting the storage container.."
  12. ## Get the storage account in which container has to be created
  13. $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
  14. ## Get the storage account context
  15. $ctx=$storageAcc.Context
  16. ## Delete a container
  17. Remove-AzStorageContainer -Container $containerName -Context $ctx -Force
  18. }
  19. DeleteStorageContainer
  20. ## Disconnect from Azure Account
  21. Disconnect-AzAccount
Open a Windows PowerShell window and navigate to the location where the script file was saved.

Run the following command.

.\script.ps1

Result:

“container003” deleted successfully.

Reference:

https://docs.microsoft.com/en-us/powershell/module/az.storage/remove-azstoragecontainer?view=azps-3.3.0

Summary:

In this blog, you saw how to delete a container from an Azure Storage Account using PowerShell.