Hey All,
Been working on a script to delete snaps automatically each night that have aged over 2 weeks. Here is my script logic.. I had thought it was solid but I just got a report this morning that the log shows it deleted a snap that was just made a day ago.. Thanks in advance for any insight !
$SnapAge = (Get-Date).AddDays(-14)<omitted>
Get-Cluster -Name *oduction* | Get-VM |
Get-Snapshot | %{ Write-Output "I've entered the Get-Snapshot loop" if ($_.Created.ToLocalTime() -lt $SnapAge) { $_ | Select @{ n="VM Name"; e={ $_.VM.Name}}, @{ n="Snap Name"; e={ $_.Name}}, @{ n="Created On"; e={ $_.Created.ToLocalTime()}}, SizeMB $LogOutput += "Removed snap from: " + $_.VM.Name + ", named: " + $_.Name $AmountReclaimed += $_.SizeMB Remove-Snapshot $_ -Confirm:$False } }