Delete all snapshots for a Blob

Delete all snapshots for a Blob

Q. How can I delete all snapshots for a blob?

A. To quickly delete all snapshots for a blob, for example a VHD, run the following PowerShell. Make sure you replace the file name, resource group and storage account variables.

$Container = 'vhds'
$VHDName = 'DummyVM201656141318.vhd'
$AzStorAccName = 'savtechsalrsscus'
$AzResGroup = 'rg-scusa'
$AzStrKey = Get-AzureRmStorageAccountKey -Name $AzStorAccName -ResourceGroupName $AzResGroup
$AzStrCtx = New-AzureStorageContext $AzStorAccName -StorageAccountKey $AzStrKey[0].Value

$VMsnaps = Get-AzureStorageBlob –Context $AzStrCtx -Container $Container | Where-Object {$_.ICloudBlob.IsSnapshot -and $_.Name -eq $VHDName -and $_.SnapshotTime -ne $null } 

foreach($VMSnap in $VMsnaps)
{
    $VMSnap.ICloudBlob.Delete()
}

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish