如何使用 REST API 获取 Azure 虚拟机中可用的所有服务?
How to get all the services available in a Azure Virtual Machine using REST API?
使用 power shell,我们可以连接到 azure 虚拟机并执行 Get-Service 命令以列出所有服务。有没有办法使用 REST API 来获取数据?
您可以在虚拟机中使用此 REST API - Virtual Machines Run Commands - Run Command
到 运行 Get-Service
,然后您可以获得服务。
请求URL:
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2019-07-01
请求body:
{
"commandId": "RunPowerShellScript",
"script": [
"Get-Service"
]
}
当你调用RESTAPI时,你会得到一个202
状态码,在body中没有响应,你需要调用另一个api在header的Location
中查看结果,查看我的答案here。
通过调用另一个 REST 检查结果 API:
使用 power shell,我们可以连接到 azure 虚拟机并执行 Get-Service 命令以列出所有服务。有没有办法使用 REST API 来获取数据?
您可以在虚拟机中使用此 REST API - Virtual Machines Run Commands - Run Command
到 运行 Get-Service
,然后您可以获得服务。
请求URL:
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2019-07-01
请求body:
{
"commandId": "RunPowerShellScript",
"script": [
"Get-Service"
]
}
当你调用RESTAPI时,你会得到一个202
状态码,在body中没有响应,你需要调用另一个api在header的Location
中查看结果,查看我的答案here。
通过调用另一个 REST 检查结果 API: