Resource Graph Shared Query - Count OS

Azure Public Test Date Azure Public Test Result

Azure US Gov Last Test Date Azure US Gov Last Test Result

Best Practice Check Cred Scan Check

Bicep Version

Deploy To Azure Deploy To Azure US Gov Visualize

This template deploys a Resource Graph shared query.

Overview

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:

  • Azure CLI

    az graph query -q "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
    
  • Azure PowerShell

    Search-AzGraph -Query "Resources | where type =~ 'Microsoft.Compute/virtualMachines' | summarize count() by tostring(properties.storageProfile.osDisk.osType)"
    
  • Portal

Microsoft.ResourceGraph

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.

Deployment steps

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.

Notes

If you are new to Azure Resource Graph, see:

If you are new to template deployment, see:

Tags: Resource Graph, KQL, query, Microsoft.ResourceGraph/queries