Microsoft Azure - Count of Azure Resources using Resource Graph Query - GeeksforGeeks

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 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.
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:
azure-virtual-machine
Cloud-Computing
Microsoft Azure
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Microsoft Azure - Azure Firewall Flow Logs From Select Source IP
Microsoft Azure - KQL Query to Get the VM Computer Properties
Microsoft Azure - Check Status of Azure VM using Azure PowerShell
Microsoft Azure - Find and Delete Orphaned Public IP addresses in Azure Portal
Defense in Depth Strategy in Microsoft Azure
Microsoft Azure - Graph Query to Get Properties of Azure VM Resource
Microsoft Azure - Resource Tagging and Best Practices
Microsoft Azure - Query System Event Log Data Using Azure KQL
Microsoft Azure - Find Orphaned Disks
Microsoft Azure - Rebooting an Application Gateway