Skip to content
Advertisement

How could I list Azure Virtual Machines using Python?

I’ve used the below code to get the Access Token from my Azure account.

https://github.com/AzureAD/azure-activedirectory-library-for-python/blob/dev/sample/certificate_credentials_sample.py

It’s working fine, I already got the token.

However, how can I use this token to list all VMs running in that subscription/resource group with Azure SDK for Python?

I guess that Microsoft documentation is a bit confusing.

Thanks.

Advertisement

Answer

You can use the function list_all()/list() to get all the VMs in the subscription/resource group, but these responses don’t show the VM running status to you. So you also need the function instance_view() to get the VM running status.

Finally, the example code to list all VMs running in that subscription/resource group below:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement