VMware Cloud Community
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Delete All Snapshots for a VM

Hi All,

Snapshots are getting deleted one by one when I am executing below Command.

I need to delete all snapshots for specific VMs on a specific Period of time so I would like to schedule the same.

Get-VM VM1 | Remove-Snapshot

Is there any way to delete all Snapshot at a time as we have option in vSphere Client.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Sort the snapshots on the Created property, the take the oldest one.

Something like this

Get-VM -Name MyVM | Get-Snapshot | Sort-Object -Property Created | Select -First 1


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Select the 1st snapshot in the tree and then add the RemoveChildren switch.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Prakas
Enthusiast
Enthusiast
Jump to solution

Alternatively you can try using the below cmdlet which also can delete all snapshots of a VM.

Get-VM VM | Get-Snapshot | Remove-Snapshot -Confirm:$false

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Hi Lucd,

Snapshot name will be unique for each VM, Is there any way to select 1st snapshot.

I have tried below that that doesn't work.

Get-VM VM1 | Remove-snapshot -snapshot * -RemoveChildren -confirm:$false

But getting error that * system.string conversion is not possible.

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

Hi Prakash,

I have tried your command but still snapshot is getting deleted one by one.

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sort the snapshots on the Created property, the take the oldest one.

Something like this

Get-VM -Name MyVM | Get-Snapshot | Sort-Object -Property Created | Select -First 1


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Sivaramsharmar
Enthusiast
Enthusiast
Jump to solution

That works fine. Below is the full command which I have used.

Get-VM -Name VM1| Get-Snapshot | Sort-Object -Property Created | Select -First 1 | Remove-Snapshot -RemoveChildren -Confirm:$false

Thank you so much Lucd.

0 Kudos