Shell scripting List and delete VMs - ganeshahv/Contrail_SRE GitHub Wiki
- Retrieve VMs using 
virsh list --all - Retrieve VMs info without the header using 
virsh list --all | tail -n +3 - Retrieve only the VMs names using 
virsh list --all | tail -n +3 | awk '{print $2}' - Delete the VMs using the following command:
 
for vmname in ` virsh list --all | tail -n +3 | awk '{print $2}'` ; do
    virsh destroy ${vmname}
    virsh undefine ${vmname}
    virsh vol-delete /home/images/${vmname}.img
done
Credits: [email protected]