How to delete a blob from Azure Storage Account using PowerShell

In this article, you will see how to delete a blob 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


Delete a blob:

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="container001"

$blobName="testscript001.docx"


## 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 Windows PowerShell window and navigate to the location where the script file was saved.

Run the following command.


.\script.ps1


Summary:

Thus in this article you saw how to delete a blob from Azure Storage Account using PowerShell.