Getting a list of all the snapshots in VMs managed by vCenter?

We have multiple ESXi servers managed by a vCenter; is there a way to get a list of all the snapshots in all the VMs?


Solution 1:

Sounds like a job for PowerCLI! Well, from a Windows workstation, anyway, which is what I have.

Get-Snapshot

The Surly Admin's blog even has a script that you can copy-pasta to get all the snapshots for all the VMs in your environment, the meat of which I'll post below for your convenience.

$Report = Get-VM | Get-Snapshot | Select VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created
If (-not $Report)
{  $Report = New-Object PSObject -Property @{
      VM = "No snapshots found on any VM's controlled by $VIServer"
      Name = ""
      Description = ""
      Size = ""
      Created = ""
   }
}
$Report = $Report | Select VM,Name,Description,Size,Created | ConvertTo-Html -Head $Header -PreContent "<p><h2>Snapshot Report - $VIServer</h2></p><br>" | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd

Solution 2:

Grrr... VMware snapshots. If I had my way, they'd only exist for backup purposes and for testing changes.

You can view the space consumed by snapshots (which is probably what you're really interested in knowing) by using the "Storage Views" tab at the cluster level in your vSphere client.

enter image description here

Start there, then drill down to the individual VMs. The entries that have values in Bytes (B) essentially mean that there are no snapshots.

Solution 3:

HopelessNoob's answer is great for a human readable report. Sometimes I prefer to parse mine into other PS objects. It is very similar too HopelessNoob's - I guess we both started from the same code snippet to build our scripts:

$VIServer = "vsphere.ad.example.com"

If (-not (Get-PSSnapin VMware.VimAutomation.Core))
{  Try { Add-PSSnapin VMware.VimAutomation.Core -ErrorAction Stop }
   Catch { Write-Host "Unable to load PowerCLI, is it installed?" -ForegroundColor Red; Break }
}

Connect-VIServer $VIServer -Credential (Get-Credential) | Out-Null

Get-VM | Get-Snapshot | Select VM,Name,Description,@{Label="Size";Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created | FT

Gives:

VM                              Name                            Description                     Size                            Created
--                              ----                            -----------                     ----                            -------
ENETSXS2                        VEEAM BACKUP TEMPORARY SNAPSHOT Please do not delete this sn... 19.28 GB                        8/11/2014 8:42:18 AM
ENETSDFS-BS                     VEEAM BACKUP TEMPORARY SNAPSHOT Please do not delete this sn... 16.30 GB                        8/11/2014 5:24:44 AM

You can then pipe that into Remove-Snapshot or filter it or whatever.