How to delete all snapshots from different subscriptions

Muni Sivakumar 0 Reputation points
2023-08-25T03:27:40.9533333+00:00

I have 500+ old snapshots in my Azure, now I have a green signal to delete them all, but I know only the manual process of how to delete them one by one, so reaching out here how to delete them fast using any script or any other process.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,018 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RevelinoB 3,675 Reputation points
    2023-08-25T04:02:42.9233333+00:00

    Hi Muni,

    Certainly, deleting a large number of Azure snapshots manually can be time-consuming. To expedite the process, you can use Azure Command-Line Interface (CLI) or Azure PowerShell to automate the deletion of multiple snapshots. Below are the steps for both methods:

    Using Azure CLI:

    1. Install Azure CLI: If you don't have Azure CLI installed, you can download and install it from the official Microsoft documentation.
    2. Authenticate: Open a terminal or command prompt and run az login to log in to your Azure account.
    3. Delete Snapshots: Run the following command to delete snapshots matching a certain criteria, such as a resource group:

    az snapshot delete --resource-group <resource-group-name> --name <snapshot-name>

    • Replace <resource-group-name> with the name of your resource group and <snapshot-name> with the name of the snapshot you want to delete. You can run this command in a loop or script to delete multiple snapshots.

    Using Azure PowerShell:

    • Install Azure PowerShell: If you don't have Azure PowerShell installed, you can install it using the following command:

    Install-Module -Name Az -AllowClobber -Scope CurrentUser

    • Authenticate: Run Connect-AzAccount to log in to your Azure account.
    • Delete Snapshots: Run the following PowerShell script to delete snapshots:
    $resourceGroupName = "<resource-group-name>"
    $snapshots = Get-AzSnapshot -ResourceGroupName $resourceGroupName
    
    foreach ($snapshot in $snapshots) {
        Remove-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshot.Name -Force
    }
    
    • Replace <resource-group-name> with the name of your resource group. This script retrieves all snapshots in the specified resource group and deletes them one by one.

    Remember to exercise caution while using automation scripts, especially when performing bulk operations like deleting resources. Always double-check the resource names and criteria before executing any script.

    Also, keep in mind that once snapshots are deleted, they cannot be recovered. Make sure you have a proper backup and retention strategy in place before performing mass deletions. This should do the trick, if you have any additional questions please let me know.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.