Ok so Im still a pretty big newbie with VMware.
I have script that deletes anything older than two weeks but I need the opposite. Would this work?
Get-VM $VMName | Get-Snapshot | Where-object {$_.Created -gt (Get-Date).AddDays(-14)} | Remove-Snapshot
Hi,
It seems it would work but remove
| Remove-Snapshot
and see if you get the desired output.
I would run this first Get-VM | Get-Snapshot | where { ( (Get-date) - $_.created).days -gt 13 } | select Name, Created That way you make sure that you are getting the correct snapshots.
If the results are what you want, I would remove the pipe for Select, and add Remove-Snapshot -confirm:false
I like getting the snapshots with the Get-Date - the $_.Created.days. I saw it a while back in the book below. It makes more sense in my head than using the AddDays(-number) I don't work for any book publisher or anyone that would make money off of the book. I did order it on Amazon.
Get-VM $VMName | Get-Snapshot | Where-object {$_.Created -lt (Get-Date).AddDays(-14)} | Remove-Snapshot