#!/bin/bash

vboxmanage list vms | awk ' {print $1} ' | awk -F',' '{gsub(/"/, "", $1); print $1}' > runningvms

while read vm_id; do
  echo $vm_id
  vboxmanage controlvm $vm_id poweroff
  vboxmanage unregistervm $vm_id --delete
done <runningvms

rm runningvms

