1
votes

I am writing a powershell script to delete blobs inside my storage account. I have a container named test and inside test I have multiple folders like "Group1", "Group2" etc upto "GroupN". And each of these folders have 1000s of blobs inside them. My goal is to write a powershell script that can delete the folder in the easiest way.

I was able to fetch the blob references but that made me iterate through the references and delete the blob individually instead of deleting the entire folder. Below is the script I have written.

$existingStorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName
$existingContainer = Get-AzureStorageContainer -Context $existingStorageAccount.Context -Name $containerName
$existingBlob = Get-AzureStorageBlob -Context  $existingStorageAccount.Context -Container $containerName -Prefix "Group1"

At this point I have the list of blobs inside the folder but then I have to loop through them which will perform poorly when I have 1000s of blobs inside the folder.

Is there a simpler way to delete the folder "Group1"?

1
This is a shot in the dark, but couldn't you use Remove-AzureStorageContainer with the -force parameter?I.T Delinquent
But that will remove every folders inside that container right? I just want to delete a specific folder inside the containerDevMJ
Found this: stackoverflow.com/questions/30523409/… It appears that the folders don't actually exist...I.T Delinquent
Thanks so looping is the only option left.DevMJ

1 Answers

2
votes

I have found this StackOverflow thread in which "Mahesh Jasti" explained that the folders aren't actually real:

It is all logical representation of folder structure and you can ignore the folders under any container

I believe looping would be your only option :)