Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 193198

Script picking up wrong snapshots

$
0
0

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        }    }

Viewing all articles
Browse latest Browse all 193198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>