Question

Nitin mulchandani on Mon, 29 May 2017 14:07:20


Hi,

I m trying to call this API https://docs.microsoft.com/en-us/rest/api/dtl/virtualmachines#VirtualMachines_Get 

I am able to get response but i need PowerState of the VM for e.g. Running, Stopped etc

I have also tried expand in the URL but it is not returning any extra data

My Code and Response

subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}?api-version=2016-05-15[&$expand]

{
"properties": {
"notes": "Windows Server 2008 R2 SP1",
"ownerObjectId": "XXXXXXXXXXXXXXXX",
"ownerUserPrincipalName": "XXXXXXXXX",
"createdByUserId": "XXXXXXXXXX",
"createdByUser": "XXXXXXXXXXX",
"createdDate": "2017-05-29T07:01:56.274567+00:00",
"computeId": "/subscriptions/XXXXXXXXXXXXXXXXXXX/resourceGroups/devtestlaboname/providers/Microsoft.Compute/virtualMachines/DevTestLabNew",
"osType": "Windows",
"size": "Standard_DS1",
"userName": "username",
"disallowPublicIpAddress": true,
"artifactDeploymentStatus": {
"artifactsApplied": 0,
"totalArtifacts": 0
},
"galleryImageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2008-R2-SP1",
"osType": "Windows",
"version": "latest"
},
"networkInterface": {},
"allowClaim": false,
"storageType": "Standard",
"virtualMachineCreationSource": "FromGalleryImage",
"provisioningState": "Succeeded",
"uniqueIdentifier": "XXXXXXXXXXXXXXXXXXXXXXXX"
},
"id": "/subscriptions/XXXXXXXXXXXXXXXXXXXX/resourcegroups/devtestlab/providers/microsoft.devtestlab/labs/devtestlab/virtualmachines/devtestlabnew",
"name": "DevTestLabNew",
"type": "Microsoft.DevTestLab/labs/virtualMachines",
"location": "westeurope"
}


Sponsored



Replies

Leo Vildosola on Mon, 29 May 2017 17:44:44


Hi Nitin,

If you look at the documentation from the link you provided, you can see the example for the $expand format (i.e. properties($expand=artifacts,computeVm,networkInterface,applicableSchedule)).

To get the PowerState, you need to expand the compute VM details, as in the following example.

subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}?api-version=2016-05-15&$expand=properties($expand=computeVm)

Nitin mulchandani on Mon, 29 May 2017 18:14:07


Thankyou so much..