Delete Azure blobs older than X number of days

This script deletes Azure blobs that are older than X days.Provide the Azure Storage Account name, access key and container name as input.A log file is created tracking the details of blobs that are deleted. Including the count of deleted blobs.You can create an Azure Automation

5 Star
3,303 times
Add to favorites
Windows Azure
E-mail Twitter Digg Facebook
  • Error in Azure Automation
    1 Posts | Last post February 12, 2020
    • Hi Manju
      I tried to implement your script in Azure Automation as PowerShell Script. Could you please let me know what I need to adjust in the runbook except the SA details. I always see the following error:
      Out-File : Cannot bind argument to parameter 'FilePath' because it is null. At line:51 char:63 + ... eleted: " $blob_count_deleted | Out-File $local_log_file_path -Append + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Out-File], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.OutFileCommand
      Thanks and regards
  • Script doesnt delete files
    3 Posts | Last post November 02, 2018
    • Hi Manju,
      I ran the script, it creates a log file but doesnt delete the files.
      In the log file it says " Purging blob from storage" but doesnt delete it.
      Can you check the script and reply if it requires any modification.
    • Hello Vishu53,
      Thank you for downloading my script. As a best practice, I comment out the cmdlet that makes changes to the system. I had commented out the below cmdlet which does the purging. I have uploaded the script again without commenting on the cmdlet. It should Remove the blobs now.
      #Remove-AzureStorageBlob -Container $container -Blob $blob_iterator.Name -Context $context
    • Hi Manju,
      Sorry for replying so late. I had already commented out the command, but still it doesnt delete. Please recheck.