Script to power off all VM’s

By | Friday, June 22, 2007

Here is at BASH script to power off all active VM’s on a host.

#!/bin/bash
IFS=’

for vm in `vmware-cmd -l`
do
        name=`vmware-cmd “$vm” getconfig displayname -q`
        state=`vmware-cmd  “$vm” getstate -q`
        if [ “$state” == “on” ]
        then
                echo “Trying to power off $name….”
                output=`vmware-cmd “$vm” stop trysoft`
            if [ $? -eq 0 ]; then
                echo “$name was powered off successfully.”
            fi
    fi
done

The script was posted by Alex at the VMTN forum a while back, but is now updated so i reports if the VM is powered off succesfully.

Leave a Reply

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