May
28
PowerShell Show VM having snapshots
Leave a comment »
By default a param minus 30 days. Save it to a *.ps1 file and it ready to use.
param ($Age = 30)
Connect-VIServer localhost
$vm = Get-VM
$snapshots = Get-Snapshot -VM $vm
Write-Host -ForegroundColor Red “Old snapshots found:”
foreach ($snap in $snapshots) {
if ( $snap.Created -lt (Get-Date).AddDays( -$Age )){
Write-Host “MachineName:” $snap.VM “Name: ” $snap.Name ” Size: ” $snap.SizeMB ” Created: ” $snap.Created
}
}