Because it’s a pain to check all VM’s for outstanding snapshots from the VI Client, this script is useful for listing any VM’s that have outstanding snapshots and when they were created. Referenced mostly from here [vSphere PowerCLI Blog]
Connect-VIServer vcenter-server.domain.com
$vms = Get-VM
$mybool = $False
foreach ($vm in $vms){
$snap = Get-Snapshot -VM $vm
if ($snap){
$mybool = $True
Write-Host "VM Name: " $vm.Name " Snapshot Name: " $snap.Name " Created: " $snap.Created
}
}
exit
In the above code the $mybool variable is used to keep track if any VM’s have snapshots or not. The purpose of this code was to send an email if any VM’s had snapshots. So, you could replace Write-Host with a string variable and write the output to that then send it via email to alert someone. You can also use the $snap.Size property to determine how big the VM’s snapshots have grown which is a good indicator on how long it will take to commit them back the the parent disk, if that is your aim.
