Search code examples
azureazure-virtual-machineazure-cliazure-cli2

How to tell if my VM is Gen1 or Gen2 in Azure?


I would like to figure out if my Azure VM (Windows + Linux) is Gen1 or Gen2. Ideally I want to get this to work via az cli or from the actual server itself. I have tried az vm list -g RG-Name -d but it does not really display this information. Does anyone know how to obtain this ?


Solution

  • Good question. The hyperVgeneration property in the VM's instance view information exposes this detail about the VM, wherein V1 indicates Generation 1 VMs and V2 indicates Generation 2 VMs.

    Using the az vm get-instance-view, you could try:

    az vm get-instance-view -g <rg-name> -n <vm-name>
    

    and look for the hyperVgeneration property in the response:

    {
    ...
      "instanceView": {
        "maintenanceRedeployStatus": null,
        "computerName": "gen2-BA",
        ...
        "hyperVgeneration": "V2",
        ...
        "osName": "Windows Server 2019 Datacenter",
        "osVersion": "Microsoft Windows NT 10.0.17763.0",
      },
    ...
    }
    

    Going one step ahead, if you want to query your Subscription for Gen1/Gen2 VMs, you can execute the following Azure CLI command:

    az vm get-instance-view --ids $(az vm list --query "[].id" -o tsv) --query '[].{VMName:name, OS:storageProfile.osDisk.osType, SKU:storageProfile.imageReference.sku, HyperVgeneration:instanceView.hyperVgeneration}' -o table
    

    The response would be similar to: List VMs

    Although the Gen2 VMs' SKU names also hint towards the Gen1 vs Gen2 distinction, hyperVgeneration should be the exact property to look for.