How to Find and Delete Old Azure Disk Snapshots in Azure?

Find and export the list of Azure Disk Snapshots older than week or month with KQL and delete Azure Disk Snapshots using Azure PowerShell Script.

Find Azure Disk Snapshots Older than 7 Days or 30 Days

Use the following Azure KQL Resource Graph Query to find the Azure Disk Snapshots older than 30 Days.

Resources
| where type =~ 'Microsoft.Compute/snapshots'
| where properties.timeCreated < now(-30d) //change Days if you wish to change

Use the following KQL Resource Graph Query to find the Azure Disk Snapshots older than 30 Days by displaying name of azure snapshot, azure resource group, azure location and snapshot creation date and time.

Resources
| where type =~ 'Microsoft.Compute/snapshots'
| where properties.timeCreated < now(-30d) //change Days if you wish to change
| project name, resourceGroup, location, TimeCreated=properties.timeCreated

Find Azure Disk Snapshot Creation Date and Time.

Resources
| where type =~ 'Microsoft.Compute/snapshots'
| project SnapshotName=name, CreationDataTime=properties.timeCreated

Use the following Azure KQL Resource Graph Query to find the Total Number Azure Disk Snapshots older than a Week (7 Days) by Subscription Count.

Resources
| where type =~ 'Microsoft.Compute/snapshots'
| where properties.timeCreated > now(-7d) 
| extend SubscriptionName=case(
subscriptionId =~ '1st Sub Id','1st Sub Name',
subscriptionId =~ '2nd Sub Id','2nd Sub Name',
subscriptionId)
| summarize count() by SubscriptionName

Use the following Azure KQL Resource Graph Query to find the Total Number Azure Disk Snapshots older than a Month (30 Days) by Subscription Count.

Resources
| where type =~ 'Microsoft.Compute/snapshots'
| where properties.timeCreated > now(-30d) 
| extend SubscriptionName=case(
subscriptionId =~ '1st Sub Id','1st Sub Name',
subscriptionId =~ '2nd Sub Id','2nd Sub Name',
subscriptionId)
| summarize count() by SubscriptionName

Use the following Azure PowerShell Script to delete a select snapshot from select Subscription in Azure.

# Switch to target Azure Subscription
$AzSubName = "add_subscription_name_here"
Set-AzureContext -SubscriptionName "$AzSubName"

# Fill Azure Disk Snapshot Details
$SnapshotName = "add_snapshot_name_here"
$RGroupName = "add_resourceGroup_name_here"

# Remove a Disk Snapshot in Azure
Remove-AzSnapshot -ResourceGroupName $RGroupName -SnapshotName $SnapshotName -Force;

Use the following Azure PowerShell Script to delete multiple snapshots within a specific Subscription in Azure.

# Switch to target Azure Subscription
$AzSubName = "add_subscription_name_here"
Set-AzureContext -SubscriptionName "$AzSubName"

# Get Azure Resource Groups
$RGs = Get-AzureResourceGroup

foreach ($RG in $RGs) {
	# Get Snapshots from Resource Groups
    $Snapshots = Get-AzSnapshot -ResourceGroupName $RG.ResourceGroupName
    foreach ($Snapshot in $Snapshots) {
        $Name = $Snapshot.Name
        $ResourceGroupName = $Snapshot.ResourceGroupName
        Write-Output "Deleteing Snapshot:$Name from ResourceGroup:$ResourceGroupName"
        Remove-AzSnapshot -ResourceGroupName $ResourceGroupName -SnapshotName $Name -Force;
        Write-Output "Snapshot:$Name from ResourceGroup:$ResourceGroupName Deleted!"
    }
}