Introduction
In this blog, you will see how to delete 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="azstorageacc1132020"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to delete a storage account
-
- Function DeleteStorageAccount
- {
- Write-Host -ForegroundColor Green "Deleting the storage account.."
- ## Check if storage account exists
- if(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName -ErrorAction SilentlyContinue)
- {
- ## Delete the storage account
- Remove-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName -Force
- }
- else
- {
- Write-Host -ForegroundColor Magenta $storageAccName "- storage account does not exist."
- }
- }
-
- DeleteStorageAccount
-
- ## Disconnect from Azure Account
- 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:
The storage account was deleted successfully.
Reference:
https://docs.microsoft.com/en-us/powershell/module/az.storage/Remove-azStorageAccount?view=azps-3.3.0
Summary:
In this blog, you saw how to delete an Azure Storage Account using PowerShell.