0

I am trying to find a REST API / PowerShell cmdlet to retrieve the VM name(starts with RD) for an instance of Azure web app.

I found out that I can list the process Ids by Instance Id and then get Instance Process with Azure App Service. This object has details including the Machine Name. I'm wondering if there is a better way of doing this, something with lesser API calls perhaps.

Background:

I need to restart a specific instance of a Azure Web app programmatically. Users calling restart can only see the VM name or Role Instance of a web App in Application insights. I found APIs to list instances but nothing to find mapping between instance Id and VM name directly.

Mia
  • 1
  • 1

2 Answers2

0

Do you try this API Virtual Machines - List?

By Using this api, you can get id and name from values[]

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines?api-version=2018-06-01

Result example :

{
  "value": [
             {
               // ignore

               "id": "/subscriptions/{subscriptionsID}/resourceGroups/test-resource-group/providers/Microsoft.Compute/virtualMachines/my-vmname",
               "name": "my-vmname"
             }
  ]
}
howie
  • 2,587
  • 3
  • 27
  • 43
  • 2
    op is asking about web apps, not vms? – 4c74356b41 Mar 19 '19 at 06:43
  • From my understanding, each instance of my Web app will run on a unique VM.I need the list of those VMs. So I'm looking for an API that takes a web app name and provides a list of instances and the VM name of where that instance is running or provide VM name for a specific instance. – Mia Mar 19 '19 at 17:58
  • If your web app's name is webapp , you shoud find instance name webapp-xxxx – howie Mar 19 '19 at 23:57
0

You can try to use the REST API Web Apps - List Instance Identifiers to get all scale-out instances of an app.

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/instances?api-version=2016-08-01

Actually, the instances for a WebApp by scaling out is for its App Service Plan. For example, I scaled up the instance number of my webapp to 4 on Azure portal, then the instance number of its App Service Plan as the figures below.

enter image description here

And I got the json response from the REST API, as below.

enter image description here

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thanks for the response. I am using this API to get the instance ID that you pointed out in the screen shot. Now I need the machine name that each instance is running on. The machine or VM name is something like RD0003FFE7494B. – Mia Mar 20 '19 at 17:21