Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to centrally remove all non-active snapshots on a vMA host before performing central backups of VMs. I am hoping such a script exists already??? Anyone know of one?


Here is a script using basic vMA tools to do the job:

# Purpose: List all snapshots for registered and powered-on VMs found on those
#          ESXi hosts listed as VI Fastpass targets (vifptarget -l).
# Author: Ryan Bowlby

# VIFP ESXi hosts
esxi_hosts=$( /usr/bin/vifp listservers | awk '$2 ~ /ESXi/ { print $1 }' )

# Have to specify an esxi target before the "--server" opt works.
first_esxi=$( echo $esxi_hosts | awk '{print $1}' )
source /opt/vmware/vma/bin/vifptarget -s $first_esxi > /dev/null 2>&1

for host in $esxi_hosts; do
   reg_vms=$( /usr/bin/vmware-cmd --server $host -l 2>/dev/null)
   for vm in $reg_vms; do
      if /usr/bin/vmware-cmd --server $host $vm getstate | grep -q 'getstate() = on'; then
         # print VM name (everything after last /) aka vm.split('/')[-1] ;)
         vm_name="`echo $(basename $vm) | sed 's/\.vmx$//g'`"
         #vm_name=$( IFS='/'; for elem in $vm; do echo $elem; done | tail -1 | sed 's/\.vmx$//g' )
         echo $vm_name
         if /usr/bin/vmware-cmd --server $host $vm hassnapshot | grep -q "1"; then
            echo $vm_name has a snapshot, removing...
            /usr/bin/vmware-cmd --server $host $vm removesnapshots
share|improve this question
I ended up creating a simple shell script to do this. Copied above. – CarpeNoctem Oct 10 '11 at 23:15
up vote 3 down vote accepted

I'm not aware of a whole script to do it but page 39 of THIS VMWare SDK document shows you how to create them using and - so I'm sure you could look at these scripts (it's too late here to do that) and see what options there are.

Obviously these are supported in your vMA.

Edit - the command you want is RemoveSnapshot_Task found HERE.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.