Need Powershell script to delete the selected snapshot of more than 30 day

Kalaimani Thirupathi 411 Reputation points
2021-05-03T13:58:31.317+00:00

Dear All,

I need a Powershell script to delete the selected snapshot of more than 30 days
one for manage disk and another unmanaged disk.

we'll provide the snapshot name in a CSV file, why because need to manage the exception

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Monalla-MSFT 13,071 Reputation points Moderator
    2021-05-05T16:53:03.707+00:00

    Hello @Kalaimani Thirupathi - Thanks for reaching out.

    In order to delete the selected snapshot of more than 30days, below is the script :

    > Get-AzSnapshot |  
    > Where-Object TimeCreated -lt (Get-Date).AddDays(-30).ToUniversalTime() |  
    > Remove-AzSnapshot  
    

    ​Try running the command without Remove-AzSnapshot first to confirm what will be deleted is accurate.

    Hope this helps.

    If the above response helped, Please "Accept as Answer" and Upvote the same so it can beneficial to the community.

    2 people found this answer helpful.

  2. Kalaimani Thirupathi 411 Reputation points
    2021-05-10T13:18:54.027+00:00

    Dear All, Can you someone help with this

    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.