Azure: Delete all *test.zip blobs from Azure Storage using Powershell Azure: Delete all *test.zip blobs from Azure Storage using Powershell powershell powershell

Azure: Delete all *test.zip blobs from Azure Storage using Powershell


Since blob storage only support individual blob deletes at this moment (i.e. it doesn't support batch deletes), your only option would be to read individual blobs from the output file and delete the blob one by one.

Based on your comments below, try the following:

$context = New-AzureStorageContext -StorageAccountName "account name" -StorageAccountKey "account key"Get-AzureStorageBlob -Container "containername" -blob *test.zip -Context $context | Remove-AzureStorageBlob

The script above will first list matching blobs and then delete them one by one.


I had this challenge when setting up Azure storage accounts for Static website hosting using Powershell in Octopus Deploy.

Here's how I fixed it:

Using the Az module for Azure Powershell I did the following:

# Define Variables$RESOURCE_GROUP_NAME = my-resource-group$STORAGE_ACCOUNT_NAME = myapplication# Get Storage Account Context$STORAGE_ACCOUNT = Get-AzStorageAccount -ResourceGroupName $RESOURCE_GROUP_NAME -AccountName $STORAGE_ACCOUNT_NAME$CONTEXT = $STORAGE_ACCOUNT.Context# Remove all test.zip Files from the $web Storage ContainerGet-AzStorageBlob -Container '$web' -Blob *test.zip -Context $CONTEXT | Remove-AzStorageBlob

OR

# Remove all Files and Folders from the $web Storage ContainerGet-AzStorageBlob -Container '$web' -Blob * -Context $CONTEXT | Remove-AzStorageBlobWrite-Host 'Removed all files and folders from the $web Storage Container'

That's all.

I hope this helps