简体   繁体   中英

How to get all the services available in a Azure Virtual Machine using REST API?

Using power shell, we can connect to azure virtual machine and execute Get-Service command to list all the services. Is there a way to fetch data using REST API?

在此处输入图片说明

You could use this REST API - Virtual Machines Run Commands - Run Command to run Get-Service in the VM, then you could get the services.

Request URL:

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2019-07-01

Request body:

{
  "commandId": "RunPowerShellScript",
  "script": [
    "Get-Service"
  ]
}

When you call the REST API, you will get a 202 status code, there is no response in the body, you need to call another api in the Location of the header to check the result, check my answer here .

在此处输入图片说明

Check the result via call another REST API:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM