Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the following Azure Resource Graph Explorer query to display a list of all virtual machines along with their corresponding core counts:

Resources | where type == 'Microsoft.Compute/virtualMachines' | join kind=leftouter (resourcecontainers | where type =~ 'microsoft.resources/subscriptions' | project subscriptionId, subscriptionName) on subscriptionId | extend coresCount = toint(tostring(properties.hardwareProfile.vmSize)[4:]) | project vmName = name, coresCount, subscriptionName

This query starts by selecting all resources of the type 'Microsoft.Compute/virtualMachines'. It then performs a left-outer join with the resourcecontainers table on the subscriptionId field to get the subscriptionName for each virtual machine.

Finally, it uses the extend operator to add a new column called coresCount, which extracts the number of CPU cores from the virtual machine's vmSize property. The resulting table is then projected to include only the virtual machine name, coresCount, and subscriptionName columns.

When you run this query in the Azure Resource Graph Explorer, you will see a list of all virtual machines in your Azure subscriptions, along with their corresponding core counts and the name of the subscription they belong to.