In this article, you will see how to delete a container from Azure Storage Account using PowerShell.
Install the Azure PowerShell Module:
Open Windows PowerShell window and run the below command.
Install-Module -Name Az –AllowClobber
Download Blob Contents:
Open a text file. Copy and paste the below script. Save the file as script.ps1.
################# Azure Blob Storage - PowerShell ####################
## Input Parameters
$resourceGroupName="psspschennairg"
$storageAccName="psspschennaistorageacc"
$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
######################################################################
Open Windows PowerShell window and navigate to the location where the script file was saved.
Run the following command.
.\script.ps1
"container003" deleted successfully.
Summary:
Thus in this article you saw how to delete a container from Azure Storage Account using PowerShell.
Comments