Introduction
In this blog, you will see how to delete a blob 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="container001"
- $blobName="testdoc"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to delete a blob
- Function DeleteBlob
- {
- Write-Host -ForegroundColor Green "Deleting the blob.."
- ## 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 Blob
- Remove-AzStorageBlob -Container $containerName -Context $ctx -Blob $blobName
- }
-
- DeleteBlob
-
- ## 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
Reference:
https://docs.microsoft.com/en-us/powershell/module/az.storage/remove-azstorageblob?view=azps-3.3.0
Summary:
In this blog, you saw how to delete a blob from an Azure storage account using PowerShell.