Search code examples
azure-virtual-machinekqlazure-resource-graph

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


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)


Solution

  • Here is another example which summarizes the total CPU counts by VM size. This can help with cost and capacity planning in Azure:

    resources 
    | where type == 'microsoft.compute/virtualmachines'
    | extend Size = tostring(properties.hardwareProfile.vmSize)
    | extend Cores = toint(extract(".+[A-Z]([0-9]+).+", 1, tostring(Size)))
    | summarize count() by Size,Cores
    | extend TotalCPUs = count_ * Cores
    | project Size, Count = count_, Cores, TotalCPUs