hostnamectl; # tested on 
   Static hostname: lenovo
  Operating System: Debian GNU/Linux 10 (buster)
            Kernel: Linux 4.19.0-17-amd64
      Architecture: x86-64

# with
virsh --version
5.0.0

libvirtd --version
libvirtd (libvirt) 5.0.0

/usr/bin/kvm --version
QEMU emulator version 3.1.0 (Debian 1:3.1+dfsg-8+deb10u8)
Copyright (c) 2003-2018 Fabrice Bellard and the QEMU Project developers

kvm qemu shutdown all vms

cat /scripts/virsh.shutdown.all.sh

#!/bin/bash
echo "=== shutting down all kvm vms ==="
for i in $(virsh list | grep running | awk '{print $2}'); do virsh shutdown $i; done
virsh list --all

# example:
/scripts/virsh.shutdown.all.sh

start all vms with keyword in name


cat /scripts/virsh.start.all.sh
#!/bin/bash
echo "=== starting all kvm vms that contain the word $1 ==="
for i in $(virsh list --all | grep $1 | awk '{print $2}'); do virsh start $i; done
virsh list --all

# example:
/scripts/virsh.start.all.sh keyword

snapshot all vms:

cat /scripts/virsh.snapshot.all.sh
#!/bin/bash
echo "=== virsh: snapshot all vms ==="
for i in $(virsh list --all | awk '(NR>2)' | awk '{print $2}'); do virsh snapshot-create $i; done
virsh list --all

# example:
/scripts/virsh.snapshot.all.sh
=== virsh: snapshot all vms ===
Domain snapshot 1628801587 created
Domain snapshot 1628801587 created
Domain snapshot 1628801587 created
Domain snapshot 1628801587 created
Domain snapshot 1628801587 created
 Id   Name               State
-----------------------------------
 -    ansible.master     shut off
 -    ansible.srv1       shut off
 -    ansible.srv2       shut off
 -    ansible.srv3       shut off
 -    debian10template   shut off
admin