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 ?
Asked
Active
Viewed 3,187 times
6

Bhargavi Annadevara
- 4,923
- 2
- 13
- 30

souser
- 5,868
- 5
- 35
- 50
1 Answers
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:
Although the Gen2 VMs' SKU names also hint towards the Gen1 vs Gen2 distinction, hyperVgeneration
should be the exact property to look for.

Bhargavi Annadevara
- 4,923
- 2
- 13
- 30
-
What's the equivalent of this in AZ Powershell? – shadowz1337 Jun 10 '22 at 10:14
-
@shadowz1337 Can you try [Get-AzVM](https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azvm?view=azps-8.0.0#code-try-5)? – Bhargavi Annadevara Jun 12 '22 at 09:32
-
1I got it working. `$Status = Get-AzVm -ResourceGroupName $VMInfo.ResourceGroupName -Name $($VM.Name) -Status` `$VM_Generation = $Status.HyperVGeneration` – shadowz1337 Jun 12 '22 at 22:22