Delete all snapshots over 30 days old

powerclisnapshotvmware-esxi

I'm currently using VMware 5.1 and looking for a method to keep snapshots that users create from becoming too old. Is there any tool inside of VMware that allows you to manage snapshots (or possibly a method to script this)?

Ideally I'd like to delete any snapshots that become over a month old automatically.

Best Answer

You can do this easily with powercli, as there is a 'remove-shapshot' cmdlet:

$oneMonthAgo = (Get-Date).AddDays(-30)
Get-VM | Foreach-Object {
Get-Snapshot -VM $_ | Foreach-Object {
if($_.Created -lt $oneMonthAgo) {
Remove-Snapshot $_ -Confirm -WhatIf
}}}

I put the -Confirm and -WhatIf in there because Remove-Snapshot could potentially do a lot of damage -- you want to make sure it's targeting the right snapshots before taking those parameters out.