skip to Main Content

The az cli command I’m running is:

az vmss list-instances --resource-group rg-name --name my-vmss-name --output json

returns instances details with osProfile.computerName for VMSS running in unified orchestration mode.
But in case of flexible orchestration it returns only basic info like instance name, but not computerName.

How can I query the instance details for VM Scale Set running in flexible orchestration mode?

That is only what I have for the flexible vmss:


{
    "id": "/subscriptions/xxxxxx",
    "instanceId": "my_instance1_fc8548e2",
    "location": "northeurope",
    "name": "my_instance1_fc8548e2",
    "resourceGroup": "my-rg",
    "type": "Microsoft.Compute/virtualMachineScaleSets/virtualMachines",
    "zones": []
  },
  {
    "id": "/subscriptions/xxxxxxx",
    "instanceId": "my_instance1_fda96383",
    "location": "northeurope",
    "name": "my_instance1_fda96383",
    "resourceGroup": "my-rg",
    "type": "Microsoft.Compute/virtualMachineScaleSets/virtualMachines",
    "zones": []
  }

For the unified vmss I have huge objects with all vm details.
The powerhsell commandlet Get-AzVmssVM also doesn’t return osprofile for running VM instances.
The instanceView=true option causes 400 error:

Operation 'VirtualMachineScaleSets.virtualMachines.GET' is not allowed on Virtual Machine Scale Set

2

Answers


  1. The az vmss list-instances command does not return the instance details with osProfile.computerName.

    VMSS Orchestration mode: Flexible

    enter image description here

    You can use the below command to fetch the computer name for each instance in the VMSS with flexible orchestration.

    vmlist=$(az vmss list-instances --resource-group <RG_name> --name <VMSS_Name> --query [].name -o tsv)
    for item in $vmlist
    do
        computer_name=$(az vm show -n $item -g <RG_name> --query osProfile.computerName -o tsv)
        echo "The VMSS instance computer name: $computer_name"
    done
    

    Output:

    enter image description here

    Reference: Orchestration modes for Virtual Machine Scale Sets in Azure

    Login or Signup to reply.
  2. To pull the computer name for each of the instances in VMscaleset in flexible orchestration you can leverage the below script.

    $vmlist= Get-AzVmssVM -ResourceGroupName {ResourceGroupName} -VMScaleSetName {VMScaleSetName} | select -property Name,ResourceGroupName
    foreach( $item in $vmlist){
        az vm show -n $item.Name -g $item.ResourceGroupName --query osProfile.computerName -o tsv
    }
    

    I have tested and it is working fine in my local environment and refer to the below screenshot for your reference.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search