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.
- ################# Azure Blob Storage - PowerShell ####################
- ## Input Parameters
- $resourceGroupName="azpractice"
- $storageAccName="azstorageacc1122020"
- $containerName="container003"
- ## Connect to Azure Account
- Connect-AzAccount
- ## Function to delete a container
- Function DeleteStorageContainer
- {
- Write-Host -ForegroundColor Green "Deleting the storage container.."
- ## Get the storage account in which container has to be created
- $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
- ## Get the storage account context
- $ctx=$storageAcc.Context
- ## Delete a container
- Remove-AzStorageContainer -Container $containerName -Context $ctx -Force
- }
- DeleteStorageContainer
- ## Disconnect from Azure Account
- Disconnect-AzAccount
Run the following command.
.\script.ps1
Result:
“container003” deleted successfully.
Reference:
Summary:
In this blog, you saw how to delete a container from an Azure Storage Account using PowerShell.

Join the conversation! Your thoughts help the community grow.