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

1

6

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 ?

Electrometer answered 10/9, 2020 at 3:2 Comment(0)
M
4

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.

Moreen answered 23/9, 2020 at 10:5 Comment(3)
What's the equivalent of this in AZ Powershell?Swale
@Swale Can you try Get-AzVM?Moreen
I got it working. $Status = Get-AzVm -ResourceGroupName $VMInfo.ResourceGroupName -Name $($VM.Name) -Status $VM_Generation = $Status.HyperVGenerationSwale

© 2022 - 2024 — McMap. All rights reserved.