VMware Tools – bulk update Windows VMs

If you need to update VMware tools on all Windows (Server 2003, XP) VMs on one or more VMware ESX server, you need to do that with command <i>vmware-vmupgrade.exe</i>.
From my point of view this command is insecure, so I deiced to create a <i>bash</i> script for this job using GREAT utility <b>vimsh</b>.

Script looks like this …
#!/bin/bash
#Automatic Upgrade VMware Tools — Nenad Vijatov — v.0.6

#Define variables
TEMPFILE=/root/temp_vmlist
RESULTFILE=/root/temp_vmupgrade

#Fill TEMPFILE
vmware-vim-cmd vmsvc/getallvms > $TEMPFILE

#Lets filter TEMPFILE
for a in `awk ‘{if ($5 == “winNetStandardGuest” || $5 == “winNetEnterpriseGuest” || $5 == “winXPProGuest”) print $1}’ $TEMPFILE`
do
#Take action on each VM
VMSTATE=`vmware-vim-cmd vmsvc/power.getstate $a | grep Powered | awk ‘{print $2}’`
echo “VM with ID $a is powered $VMSTATE” >> $RESULTFILE
while [ $VMSTATE == “off” ]
do
echo “Powering on VM with ID $a …” >> $RESULTFILE
vmware-vim-cmd vmsvc/power.on $a
sleep 30
VMSTATE=`vmware-vim-cmd vmsvc/power.getstate $a | grep Powered | awk ‘{print $2}’`
done
echo “Upgrading VM with ID $a …” >> $RESULTFILE
vmware-vim-cmd vmsvc/tools.upgrade $a
done
#EOF