Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Microsoft Azure – Count of Azure Resources using Resource Graph Query

  • Last Updated : 16 Dec, 2021

Graph Query is Azure can be easier to understand if you are familiar with  Querying languages like SQL.  In this article, we will keep track of the Azure resources using the Resource Query graph.

For this first open the Azure Resource Graph Explorer in Azure Portal to Run the following below Queries

1. To get the Total Count of Azure Resources from the select directory or management group or subscription scope.

  • KQL Graph Query: This query returns the number of Azure resources that exist in the select directory or management group or subscription scope.
Resources
| summarize count()

Output:

2. To get the Total Count of Azure Virtual Machines from a select directory or management group or subscription scope.

  • KQL Graph Query: This query returns the number of virtual machines that exist in the select directory or management group or subscription scope.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| count
| project TotalVMs = Count

Output:

3. To get the Count virtual machines by OS type (Windows and Linux)from select directory or management group or subscription scope.

  • KQL Graph Query:  This query returns the number of virtual machines by OS type that exists in the select directory or management group or subscription scope.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| summarize count() by tostring(properties.storageProfile.osDisk.osType)

Output:

4. To get the Total Count of Azure Virtual Machines by Location from a select directory or management group or subscription scope.

  • KQL Graph Query: This query returns the number of virtual machines by the location that exists in the select directory or management group or subscription scope.
Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| summarize count() by 

tion

Output:

5. To get the Total Count of Azure Virtual Machines by Select Specific Location from select directory or management group or subscription scope.

Example 1:This KQL Graph Query returns the number of virtual machines by selecting the location where it has “westeurope” that exists in the select directory or management group or subscription scope.

Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| where location =~ 'westeurope'
| count

Output:

Example 2: This  KQL Graph Query returns the number of virtual machines by selecting the location where it has “eastus” that exist in the select directory or management group or subscription scope.

Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| where location =~ 'eastus'
| count

Output:

6. To get the Count Azure Key Vault Resources from the select directory or management group or subscription scope.

  • KQL Graph Query: This query returns the number of key vault resources that exist in the select directory or management group or subscription scope.
Resources
| where type =~ 'microsoft.keyvault/vaults'
| count

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!