Script para ver los snapshot date

# vCenter server name or IP
$vcenter = "vCenter5"
# Max number of snapshots to allow per VM
$maxsnapcount = 1
# Max age of any snapshot to allow in hours
$maxsnapage = 18
# Display all VM messages?
$displayall = $true
#region Code
cls
### Static Variables
# Array containing all snapshots found
[array]$allsnapshots = $null
# Current date minus snapshot max date
$date = (Get-Date).AddHours(-1 * $maxsnapage)
### Gather Inventory
Connect-VIServer $vcenter | Out-Null
$vms = Get-VM | Get-View
Foreach ($vm in $vms)
{
If ($vm.Snapshot -ne $null)
{
# Inventory the VM snapshots
[array]$vmsnapshots = Get-VM -Id $vm.MoRef | Get-Snapshot
# Add the snapshots to the master array
$allsnapshots += $vmsnapshots
# Check to see if the VM has exceeded the max snapshot age
Foreach ($snap in $vmsnapshots)
{
If ($snap.Created -le $date) {Write-Host -ForegroundColor:DarkRed "[Old Snapshots] $($vm.name) contains an old snapshot named $($snap.Description) created on $($snap.Created)"}
}
# Check to see if the VM has exceeded the max snapshot count
If (($vmsnapshots.count) -gt $maxsnapcount)
{
Write-Host -ForegroundColor:DarkRed "[Max Snapshots] $($vm.name) has $($vmsnapshots.count) snapshots"
}
}
ElseIf ($displayall -eq $true) {Write-Host -ForegroundColor:DarkGreen "$($vm.name) has no snapshots"}
}
# Summary Information
Write-Host "==============================`nSummary Information`nFound $($vms.count) VMs`nFound $($allsnapshots.count) snapshots"
#endregion

Imagen de la salida de este script

Comentarios