This is the script I'm working with. Install PowerCLI on a server, save this script as a PowerShell script, and create a scheduled task.
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer -Server YourvCenterServerName
Get-VM | `
Get-Snapshot | `
Where-Object { $_.Created -lt (Get-Date).AddDays(-0) } | `
Remove-Snapshot -Confirm:$False -Whatif
As is, this will delete ALL snapshots in your environment that are older than X days (0 in the case above). I'm trying to figure out how to make it only delete snapshots in a certain resource pool.
This is a suggestion I found from someone on the boards, but it is still deleting snapshots in all resource pools. It's supposed to exclude rp1 and rp2.
Add-PSSnapin VMware.VimAutomation.Core
Connect-VIServer -Server YourvCenterServerName
Get-ResourcePool | Where {"rp1","rp2" -notcontains $_.Name} | `
Get-VM | `
Get-Snapshot | `
Where-Object { $_.Created -lt (Get-Date).AddDays(-0) } | `
Remove-Snapshot -Confirm:$False -Whatif
Anyone have any ideas of what I'm doing wrong, or how I could exclude certain resource pools?
(For testing, I added -Whatif and made the days -0. So you'll want to remove/change those as needed.)