2015-11-01 127 views

回答

1

您可以使用虚拟机REST API Get information about a virtual machine为天青资源管理,请参考https://msdn.microsoft.com/en-us/Library/azure/mt163682.aspx

在REST API为Get information about the instance view of a virtual machine的响应,就可以找到JSON属性"statuses"阵列中的第二元件的属性displayStatus的参考页的底部,参见下面的图:

enter image description here

0

您可以在门户网站上看到VM的状态。如果你想使用powershell-Get-azurevm -servicename "svcname" -vmname "vmname"

也会给你vm的状态。

2

请尝试下面的代码。 PowerState是你需要检查的。

 using (ComputeManagementClient computeClient = new ComputeManagementClient(credentials)) 
     { 
      HostedServiceListResponse services = await computeClient.HostedServices.ListAsync(); 
      foreach(HostedServiceListResponse.HostedService service in services.HostedServices) 
      { 
       DeploymentGetResponse deployment = await computeClient.Deployments.GetBySlotAsync(service.ServiceName, DeploymentSlot.Production); 

       var powerState = deployment.RoleInstances[0].PowerState; 

      } 
     }