Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Storage/Powershell/DeleteAllSnapshotsUsingEntraAuth
Original file line number Diff line number Diff line change
@@ -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
}
}
}