RvdNieuwendijk
Leadership
Leadership

Geob,

to delete all the snapshots that are older then 3 days you can do the following:

Get-VM  | `
  Get-Snapshot |  `
  Where-Object { $_.Created -lt (Get-Date).AddDays(-3) } | `
  Remove-Snapshot

If you save this script as C:\Remove-SnapshotsOlderThen3Days.ps1 you can schedule it if you run the next Windows command:

%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{C:\Remove-SnapshotsOlderThen3Days.ps1}"

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos