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.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. $containerName="container001"
  6. $blobName="testdoc"
  7. ## Connect to Azure Account
  8. Connect-AzAccount
  9. ## Function to delete a blob
  10. Function DeleteBlob
  11. {
  12. Write-Host -ForegroundColor Green "Deleting the blob.."
  13. ## Get the storage account in which container has to be created
  14. $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
  15. ## Get the storage account context
  16. $ctx=$storageAcc.Context
  17. ## Delete Blob
  18. Remove-AzStorageBlob -Container $containerName -Context $ctx -Blob $blobName
  19. }
  20. DeleteBlob
  21. ## Disconnect from Azure Account
  22. 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.