Azure Resource Graph Queries by Resource Type

The Azure Resource Graph provides the ability query and explore your azure resources at scale. That is across all your subscriptions.

I will show options to find the resource type that is be used in your resource graph query. You may ask how to query for storage account resource types and need to find the exact string token or value. (e.g. microsoft.storage/storageaccounts )

A resource graph query returns the following property fields:

  • Id
  • sku
  • name
  • type
  • kind
  • plan
  • tags
  • aliases
  • location
  • properties
  • resourceGroup
  • subscrionId
  • managedBy
  • identity
  • tenantId
  • ResourceId

The type field is the resource type.

Upon executing the query:

Search-AzureRmGraph -Query "project name, type,
resourceGroup" | Out-GridView

I get a result of my azure resources and the type.

The type field is the Resource Type in the format of <Provider Namespace>/<Resource Type>

For further details, read Azure resource providers and types

To find out all resource providers registered and their resource types, execute the following for a friendly output:

 ForEach ($i in (Get-AzureRmResourceProvider -ListAvailable | Where-Object { $_.RegistrationState -eq 'Registered' }))
{
    ForEach ($j in $i.ResourceTypes)
    {
        write-host $i.ProviderNamespace ‘/’ $j.ResourceTypeName 
    }    
} 

A sample output:

For a list of all resource types where an azure resource has been deployed, simply execute:

Search-AzureRmGraph -Query "distinct type"

This is probably the most practical option.

So if you are wondering, how do I query for all storage accounts that have been deployed, you can find in the above list microsoft.storage/storageaccounts

And then execute

Search-AzureRmGraph -Query "where
type=='microsoft.storage/storageaccounts' | project name,
resourceGroup,subscriptionId"

Here are other sample queries of mine:

# Find deployed resource types in my azure subscriptions
Search-AzureRmGraph -Query "distinct type"
# How may types of resource per resource group?
Search-AzureRmGraph -Query "summarize count() by type, resourceGroup, subscriptionId | order by type, resourceGroup asc"
Search-AzureRmGraph -Query "where type=='microsoft.keyvault/vaults' | summarize count() by resourceGroup, subscriptionId | order by subscriptionId" | Out-GridView
Search-AzureRmGraph -Query "where type=='microsoft.compute/virtualmachines' | summarize count(type) by subscriptionId, type | order by type, subscriptionId" | Out-GridView
Search-AzureRmGraph -Query "where type=='microsoft.web/sites' | summarize count(type) by subscriptionId, type | order by type, subscriptionId" | Out-GridView
Search-AzureRmGraph -Query "where type=='microsoft.web/sites' | project name, subscriptionId, type | order by type, subscriptionId" | Out-GridView
Search-AzureRmGraph -Query "where type=='microsoft.storage/storageaccounts' | project name, resourceGroup,subscriptionId"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s