Resource Graph Shared Query - Count OS
This template deploys a Resource Graph shared query.
This template deploys an Azure Resource Graph shared query. The shared query counts all virtual machines, and then summarizes the title broken down by Operating System (OS).
Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)
This query can be manually run through the following methods:
az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
- Azure portal: portal.azure.com
- Azure Government portal: portal.azure.us
- Azure China portal: portal.azure.cn
The Microsoft.ResourceGraph resource provider is used by Resource Graph Explorer in the portal to save shared queries. A shared query is an Azure Resource Manager object while a private query is stored in a users profile.
- queries: This is the resource type of a shared query used in Azure Resource Graph Explorer.
You can click the "Deploy to Azure" button at the beginning of this document or follow the instructions for command line deployment using the scripts in the root of this repo.
If you are new to Azure Resource Graph, see:
- Azure Resource Graph documentation
- Azure Resource Graph - Understand the query language
- Azure Resource Graph - Starter queries
- Azure Resource Graph - Advanced queries
- Azure Resource Graph - Get resource changes
If you are new to template deployment, see:
Tags: Resource Graph, KQL, query, Microsoft.ResourceGraph/queries