vSphere PowerCLI – Snapshot handling

Snapshots are cool. We all use them, we all love them. But they can be tedious to manage, and this can lead to them causing issues.

Take some care to manage them proactively so they don’t become a monkey on your back.

I’ve grown rather fond of managing snapshot functions using PowerCLI. Why? It’s fast, efficient and everything looks cooler from a command shell, right? Impress your friends and colleagues !

Let’s create a quiesced snapshot called “Snapshot #4 20062014a” on the guest called “TEST-VM”

s1

List all the snapshots for this vm;

s2

Let’s list all snapshots that are residing in the connected vCenter server’s inventory; (This cmd can take considerable time if you have a large inventory.)

s3

 (Many people still use the old method Get-vm |Get-Snasphot which is slower than this method. When using the method I describe, you can omit the –VM & -Name parameters also)

By default this sort of output is not very meaningful.

Which guests are they? How old are the snapshots? How big are they?

Let’s make it useful by listing the snapshots older than 2 days and include the vm name, the snapshot name, the description and the size in GB’s and then sort by the VM name;

s4

 (The ‘Expresssion’ parameter limits the output to 2 decimal places)

Now it’s much more useful.

Now let’s delete that first snapshot we created;

s5

Finally, remove all snapshots for TEST-VM.

 

s6

Note that I have used the ‘-Confirm:$false’ parameter here, which will remove all snasphots without prompting for any confirmation, so use with caution.

While knowing and being familiar with these commands will help in ad-hoc and day to day situations, having a more holistic approach is also beneficial. I’m a fan/support of the vCheck scripts which can be downloaded from Virtua-Al.net here. Check them out.

Good luck !

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: