Open In App

Microsoft Azure – Count of Azure Resources using Resource Graph Query

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.

Resources
| summarize count()

Output:



2. To get the Total Count of Azure Virtual Machines from a 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.

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.

Resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| summarize count() by location

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.

Resources
| where type =~ 'microsoft.keyvault/vaults'
| count

Output:

Article Tags :