Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Azure CLI – Query Power state of a virtual machine

I would love to query VMs powerstate with azure cli in bash

Mine goal is to stop a virtual machine, but before that check if the machine was already stopped and vise versa.

So I need to get the powerstate of a specific VM, but I don’t see az vm list have that as a parameter. How could that be achieved?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I tried to reproduce the same in my environment and got the results successfully like below:

To check Power state of the Azure Virtual Machine, please use the below command:

az vm show -g ResourceGroupName -n testvm -d --query powerState

enter image description here

The command will give the status of the specific Azure VM. And based on that you can Start/Stop the Azure Virtual Machine.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading