1

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"?

DevMJ
  • 331
  • 1
  • 5
  • 17
  • This is a shot in the dark, but couldn't you use Remove-AzureStorageContainer with the -force parameter? – I.T Delinquent Jun 12 '19 at 09:46
  • But that will remove every folders inside that container right? I just want to delete a specific folder inside the container – DevMJ Jun 12 '19 at 10:00
  • Found this: https://stackoverflow.com/questions/30523409/delete-folders-inside-azure-blob-storage-container/30591550 It appears that the folders don't actually exist... – I.T Delinquent Jun 12 '19 at 10:02
  • Thanks so looping is the only option left. – DevMJ Jun 12 '19 at 10:06

1 Answers1

2

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 :)

I.T Delinquent
  • 2,305
  • 2
  • 16
  • 33