Azure Resource Graph Explorer :: list all VMs with number of cores

2.2k Views Asked by At

GOAL: I want to list all VMs in our park with the relative number of cores.

In order to do so I found this query :

Resources
| where type=~ 'microsoft.compute/virtualmachines'
| project subscriptionId, name, location, resourceGroup, Capacity = toint(sku.capacity), Tier = sku.name
| order by Capacity desc

PROBLEM: the query return the column Capacity but they are all null

(Also solution in PowerShell will be accepted if they allow export to CSV)

1

There are 1 best solutions below

1
On BEST ANSWER

I tried to reproduce the same in my environment.

Tried with the following query:

vmCore=tostring(properties.hardwareProfile.vmSizeProperties.NumberOfCores)

But not able to get number of cores .

As i do not have them enabled in my portal to display in Json of my Virtual machine template too.

enter image description here

As i also Tried with properties.hardwareProfile.vmSizeProperties

Graph query:

Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| project name, properties.vmId, properties.storageProfile.osDisk.osType,properties.hardwareProfile.vmSize,properties.hardwareProfile.vmSizeProperties
| order by ['name'] asc

Everything like hardware profile is resulting in output except vm size properties are empty which includes number of cores property for vmsize properties where it has to have number of cores.

enter image description here

Try Initially check the properties and then call the number of cores for each VM. Below command gives VM size particularly.

Command:

$Myvm= Get-AzureRmVM -ResourceGroupName myrg  -Name myacctvm

enter image description here

Command:

$MyVmZizeProperties = Get-AzureRmVMSize -ResourceGroupName myrg -VMName myacctVM

enter image description here

$NumberOfCores = $MyVmZizeProperties.NumberOfCores

enter image description here

$MyVmZizeProperties = Get-AzureRmVMSize -ResourceGroupName myrg   -VMName myacctVM   | Export-Csv -Path C:\vmproperties.csv -NoTypeInformation

Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/resource-graph-samples?tabs=azure-cli