List all VMID's from command line?

kwolf72

New Member
Aug 23, 2012
8
0
1
Is there a way to list all VMID's used in a cluster of multiple nodes from the command line?

qm is specific to each node. pvecm only shows information about nodes, but not their VM's.

I really want to script up some VM creations, but I'm having problems figure out how to get some of the information I need, and pass parameters.

Thanks,
Kevin.
 
The pvesh list doesn't tell use the name of the vm and there's no way to tell which are template.
I've been searching around and cannot find how to list all vm in the cluster but also have their names and whether it's a template or not.
qm list isn't working either as no cpu info nor template or not...
How do you guys handle vm inventory using cli??
 
pvesh get /cluster/resources --type vm --output-format json contains both the 'template' boolean and the 'name' property (the same API call is used for the tree in the GUI)
 
  • Like
Reactions: Robert.H
well, the default lists some sane default - this can be the whole response if it is small, but it can also be some subset if the response contains too much data to sensibly display in a table/human readable output :)

we try to document the API return values in our api-viewer - http://pve.proxmox.com/pve-docs/api-viewer/index.html feel free to send patches or pings if you see something missing
 
  • Like
Reactions: aasami
Code:
pvesh get /cluster/resources --type vm --output-format yaml | egrep -i 'vmid|name' | paste - - -d,

Is how I do this. You can direct the output to a file or pipe it into the next command. You can obviously filter (egrep) for whatever parameters you need / want etc
 
pmxc can do that.

Code:
$ pmxc lxc list pve01
+------------+-------+----------------------+------------+--------+--------+--------+--------------------------+-------------------------------------+
|    Node    | VMID  |       Hostname       |   Status   |  Arch  | Rootfs | Memory |           IPv4           |                IPv6                 |
|            |       |                      |            |        | (GiB)  | (MiB)  |                          |                                     |
+============+=======+======================+============+========+========+========+==========================+=====================================+
| pve01      | 102   | ipam01               | running    | amd64  | 8G     | 2048   | 10.167.160.2/24 (eth0)   |                                     |
+------------+-------+----------------------+------------+--------+--------+--------+--------------------------+-------------------------------------+
| pve01      | 100   | mariadb01            | running    | amd64  | 150G   | 4096   | 10.167.160.11/24 (eth0)  |                                     |
+------------+-------+----------------------+------------+--------+--------+--------+--------------------------+-------------------------------------+

also pmxc lxc list pve01 -f json
 
I know that this post is a bit older. Needed something similiar. Here we go:
Bash:
pvesh get /cluster/resources -type vm --output-format yaml | egrep -i 'vmid|name' | sed 's@.*:@@' | paste - - -d ""

Gives a nice list of VM name and it's id.
 
If you are using linux you might find this to be of help

Bash:
pvesh get /cluster/resources --type vm --human-readable --noborder | awk '(NR!=1)'| awk '{printf " %s\n", $13}'|sort

This will get the name of the vm's. Each column is a number so $13 is the column with the name.
 
Last edited:
  • Like
Reactions: nem8 and Kosh
If you are using linux you might find this to be of help

Bash:
pvesh get /cluster/resources --type vm --human-readable --noborder | awk '(NR!=1)'| awk '{printf " %s\n", $13}'|sort

This will get the name of the vm's. Each column is a number so $13 is the column with the name.
Hi,

I don't have a "name" column :

1632820075686.png

Do i miss something ?
 
some more notes

to get all vmids

Code:
# pvesh get /cluster/resources --type vm --output-format json | jq '.[] .vmid' -r

or name and vmid as a TSV

Code:
# pvesh get /cluster/resources --type vm --output-format json | jq '.[] | [.vmid, .name] |  @tsv' -r
9001    ubuntu2204-templ
 
# pvesh get /cluster/resources --type vm

or

# cat /etc/pve/.vmlist

or you simply scan all dirs in /etc/pve/nodes/

or you use the REST API.
How often does #cat /etc/pve/.vmlist get updated? Are any of these methods more or less accurate?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!