To display the state (Running, Deallocated etc) of our VM’s, I currently use the following command and this works fine.
az vm list -o table -d -g ....
With the number of VM’s increasing on a regular basis, this is getting very cumbersome. For 200 VM’s, I need to run this command 200 times.
Is there an easier way to obtain this information, by querying GraphAPI maybe ?
2
Answers
I have reproduced in my environment and Thanks to @volody, followed his SO-thread and below is the query to run in Azure Resource Graph explorer:
References taken from:
Edit 2:
Yes you can get different vms using names as below:
I used has :
| where name has "x" or name has "y"
You can use the "–query" parameter to get the names of VMs which have a particular text in names(At the start). The ! is ignoraing the VMs which names start with ‘E2E’.
There are other conditions as well which are taken by –query.
[https://learn.microsoft.com/en-us/cli/azure/query-azure-cli?tabs=concepts%2Cbash][1]
If you do not have some naming rules which you can use to get the names of those 200 VMs then you need to think about using a naming convention as you cant do any thing except do them manually.
What you can also do is create the list one time, everytime you have a new VM add the new name to that list. import that list as an array and then run the command to get the status of each one at a time using a loop.