0

I know I can use Get-ASzVmssVM to get a list of instances in a VMSS. But how can I retrieve the application healthy status? The Azure UI does this when you look at Instances for the scale set. Is there any mechanism for me to do the same?

Get-AzVmssVM -InstanceView -ResourceGroupName $resourceGroupName -VMScaleSetName $scaleSetName

I'd like to iterate unhealthy instances and restart them. Often times the VMSS is larger than 200 instances, so Azure won't do this by default for me.

Frank
  • 1,261
  • 2
  • 9
  • 9

1 Answers1

2

You can find application health status in the instanceView of an instance:

$allInstances = Get-AzVmssVM -InstanceView -ResourceGroupName $rg -VMScaleSetName $vmssName
$unhealthyInstances = $allInstances | where {$_.InstanceView.VmHealth.Status.Code -eq "HealthState/unhealthy"}
Write-Output "Total instances:  $($allInstances.Count)"
Write-Output "Unhealthy instances:  $($unhealthyInstances.Count)"

More

fitzgeraldsteele
  • 4,547
  • 3
  • 24
  • 25
  • Also, Azure has Automatic Instance Repair, which can automatically delete unhealthy instances and create new ones https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-automatic-instance-repairs – fitzgeraldsteele Apr 08 '21 at 16:46