From 3623cdfda4940ec917380bf6989a202696a87369 Mon Sep 17 00:00:00 2001 From: Thakur Mishra Date: Wed, 17 Dec 2025 13:48:34 +0530 Subject: [PATCH] Create DeleteAllSnapshotsUsingEntraAuth script helps to delete all snapshots iterating through all the container in a storage account and using Entra authentication --- .../DeleteAllSnapshotsUsingEntraAuth | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Storage/Powershell/DeleteAllSnapshotsUsingEntraAuth diff --git a/Storage/Powershell/DeleteAllSnapshotsUsingEntraAuth b/Storage/Powershell/DeleteAllSnapshotsUsingEntraAuth new file mode 100644 index 0000000..0f013a8 --- /dev/null +++ b/Storage/Powershell/DeleteAllSnapshotsUsingEntraAuth @@ -0,0 +1,42 @@ +#This PowerShell script helps to delete all snapshots iterating through all the container in a storage account and using Entra authentication + +#Disclaimer +#By using the following materials or sample code you agree to be bound by the license terms below +#and the Microsoft Partner Program Agreement the terms of which are incorporated herein by this reference. +#These license terms are an agreement between Microsoft Corporation (or, if applicable based on where you +#are located, one of its affiliates) and you. Any materials (other than sample code) we provide to you +#are for your internal use only. Any sample code is provided for the purpose of illustration only and is +#not intended to be used in a production environment. We grant you a nonexclusive, royalty-free right to +#use and modify the sample code and to reproduce and distribute the object code form of the sample code, +#provided that you agree: (i) to not use Microsoft’s name, logo, or trademarks to market your software product +#in which the sample code is embedded; (ii) to include a valid copyright notice on your software product in +#which the sample code is embedded; (iii) to provide on behalf of and for the benefit of your subcontractors +#a disclaimer of warranties, exclusion of liability for indirect and consequential damages and a reasonable +#limitation of liability; and (iv) to indemnify, hold harmless, and defend Microsoft, its affiliates and +#suppliers from and against any third party claims or lawsuits, including attorneys fees, that arise or result +#from the use or distribution of the sample code." + +Connect-AzAccount + +$mysubscriptionId = "f80fee09-e666-48bd-9820-e5be4fdf4e39" +$mystorageAccountName = "strorage0nonhns0lrs0stan" + +Select-AzSubscription -Subscription $mysubscriptionId +$ctx = New-AzStorageContext -StorageAccountName $mystorageAccountName -UseConnectedAccount + + +$mycontainers = Get-AzStorageContainer -Context $ctx +foreach ($con in $mycontainers) +{ + $blobsnapshot= Get-AzStorageBlob -Container $con.Name -Context $ctx -IncludeDeleted + + foreach($blob in $blobsnapshot) + { + Write-Host $blob.Name + if(($blob.SnapshotTime -ne $null) -and ($blob.IsDeleted)) + { + Write-Host -ForegroundColor Yellow $blob.Name $blob.IsDeleted + Remove-AzStorageBlob -Container $con.Name -DeleteSnapshot $blob.Name -Context $ctx + } + } +}