Ask Your Question
0

How can I use the Azure Resource Graph Explorer to display a list of all virtual machines along with their corresponding core counts?

asked 2023-06-07 15:48:50 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-07 16:18:02 +0000

nofretete gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 15:48:50 +0000

Seen: 9 times

Last updated: Jun 07 '23