Oumar Diarra
Oumar Diarra

Reputation: 365

Get Azure VM status : "running , stopped" using resource manager deployment and rest api

i've deployed a vm using Resource Manager deployment model.

Using rest api as described here: https://msdn.microsoft.com/en-us/library/azure/mt163682.aspx i'm able to get informations about my VM. But i cannot see if the VM is running or not. I want that information to start/stop the VM Automatically via code.

Does anyone have tried that and get the VM powerstate?

best regards...

i make a GET using this URI

string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}?api-version={3}", subscriptionID, resssourcegroup, vmname,apiversion);

apiversion is 2016-03-30.

Upvotes: 0

Views: 5159

Answers (3)

Alfredo Fernandez
Alfredo Fernandez

Reputation: 13

This is the link to the documentation where you can see the Status of the VM: https://learn.microsoft.com/en-us/rest/api/compute/virtual-machines/instance-view?tabs=HTTP

This is an example of the output

"statuses": [
    {
        "code": "ProvisioningState/succeeded",
        "level": "Info",
        "displayStatus": "Provisioning succeeded",
        "time": "2022-07-25T02:12:52.7726725+00:00"
    },
    {
        "code": "PowerState/running",
        "level": "Info",
        "displayStatus": "VM running"
    }
]

Upvotes: 0

Neha
Neha

Reputation: 11

The API call for this information is:

https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/Microsoft.Compute/virtualMachines/{vm-name}/InstanceView?api-version={api-version}

Upvotes: 1

Oumar Diarra
Oumar Diarra

Reputation: 365

Needed to use the second request uri "Get information about the instance view of a virtual machine" from the following url https://msdn.microsoft.com/en-us/library/azure/mt163682.aspx to get the instance powerstate.

Thank you.

Upvotes: 0

Related Questions