VMware snapshots can be a very good insurance policy when making changes to a VM. Its also important to make sure not to leave old snapshots laying around as this will cause you problems later. Depending on the amount of VMs you have, it may be difficult and time consuming to manually go thru all your VMs to check for snapshots. In this blog I will explain a few techniques I have used to report on VM snapshots. We will be using the “Get-VM” cmdlet and piping it to the “Get-Snapshot” to get the information we need in the examples below. To do anything with PowerShell in VMware you will need to install VMware vSphere PowerCLI. You will then need to open PowerCLI connect to your VMWare vCenter server by typing “Connect-VIServer vCenterServerName”.
To get a list of all VM Snapshots for VMs managed by vCenter you can type the following command:
get-vm | get-snapshot | format-list
The command above will give you the following properties:
After seeing a list of properties for all VMs with snapshots, you may decide you only want to see certain properties. For example, you want to list all VMs with snapshot but you only want list the VM and the name of the snapshot you could simply add these properties after “Format-List” as shown below:
get-vm | get-snapshot | format-list vm,name
If you would like to write that information to a text file for later review or to send it to other Admins so they may clean up their mess, type the same command as above but use the “Out-File” cmdlet to pipe it to text file. In this example we pipe the output to a file on the C drive named snaps.txt:
get-vm | get-snapshot | format-list | out-file c:\snaps.txt
Now lets say you want a list of snapshots for only a subset of virtual machines in vCenter and you have your VMs organized in different folders under “VMs and Templates”. In this case you can run the command so it only targets a particular folder. For example if you had a folder in vCenter that contains 5 lab virtual machines and the name of the folder was called “My Lab”, you would type the following command to list all snapshots for VMs in the “My Lab” folder:
get-vm -location “My lab” | get-snapshot | format-list
I hope that this will give you a quick and easy way to get a good inventory of you Virtual Machine Snapshots as well help in keeping your environment clean. If you have any comments please feel free to post!