ESXi 4 Quick and Easy Find and Remove All Snapshots Via CLI

Cute_oh_snap_gingerbread_man_cookie_photosculpture-p1534174383042537603s98_400I needed a way to find and remove all snapshots quickly and easily from the ESXi 4 command line. Note that I am not a Windows user and would rather punch myself square in the face than use PowerShell.

So here it is… and let me warn you its really nasty

 

1
<p><span style="color:#8a9b55;"><strong># for vm in `vim-cmd vmsvc/getallvms | awk '{ print $1 }' | grep -v Vmid`</strong></span><br /><span style="color:#8a9b55;"><strong>&gt; do

                                  
> vim-cmd vmsvc/snapshot.removeall $vm
> done

Note that this could actually take a really long time to run depending on the size of your snapshots.

Basically it finds the vmid of each and every vm running on the box and attempts to remove any snapshots (if they exist). Note that you will need to do this on every node in your cluster.  I plan to write a better version of this script at somepoint that will search the datastores for snapshots and the derive the vmid from that, but not today.

Advertisements

One thought on “ESXi 4 Quick and Easy Find and Remove All Snapshots Via CLI

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.