Cloud and Datacenter Management Blog

Microsoft Hybrid Cloud blogsite about Management

Microsoft Azure Resource Graph is a Powerful Tool #Azure #Cloud #AzOps #Kusto #PowerShell

Leave a comment


Welcome to Azure Resource Graph

Azure Resource Graph is a service in Azure that is designed to extend Azure Resource Management by providing efficient and performance resource exploration with the ability to query at scale across a given set of subscriptions so that you can effectively govern your environment. Azure Resource Graph enables full visibility into your environments by providing high performance and powerful query capability across all your resources.

From here you can experience the power of Azure Resource Graph by doing it yourself.

Https://shell.azure.com

You can use Microsoft Azure Resource Graph with different language support like :

  • With Azure CLI
  • With PowerShell
  • With Kusto in Azure Resource Graph Explorer

Start here when you like to work with Microsoft Azure CLI

From here we are going further with Azure PowerShell and Azure Resource Graph in CloudShell.
Login to https://shell.azure.com

Type following command : Install-Module -Name Az.ResourceGraph

Type Y

Type the Following Command: Get-Command -Module ‘Az.ResourceGraph’ -CommandType ‘Cmdlet’

From here we can start with Search in Azure Resource Graph

The first step to understanding queries with Azure Resource Graph is a basic understanding of the Query Language. If you aren’t already familiar with Azure Data Explorer, it’s recommended to review the basics to understand how to compose requests for the resources you’re looking for.

Samples


Command : Search-AzGraph -Query ‘Resources | project name, type | limit 5’

Without the Limit 5 you get all of your resources.

Command: Search-AzGraph -Query ‘Resources | project name, type | limit 10 | order by name asc’

Command: Search-AzGraph -Query “Resources | summarize count()”


Command: Search-AzGraph -Query “Resources | project name, location, type| where type =~ ‘Microsoft.Compute/virtualMachines’ | order by name desc”

Command: Search-AzGraph -Query “Resources | where type =~ ‘Microsoft.Compute/virtualMachines’ | project name, properties.storageProfile.osDisk.osType | top 15 by name desc”


Command: Search-AzGraph -Query “Resources | where type contains ‘publicIPAdresses’ and isnotempty(properties.ipAddress) | project properties.ipAddress | limit 100”

Handy to see your External IP Addresses in Azure 😉


Command: Search-AzGraph -Query “Resources | where tags.environment=~’internal’ | project name”

To find tour Tagged Resources in Azure.


Microsoft Azure Resource Graph Explorer in the Portal.

Here you can make your kusto queries and save them for Colleagues by sharing them.

Sharing your Kusto queries

Resources
| where type =~ ‘microsoft.compute/virtualmachines’
| extend nics=array_length(properties.networkProfile.networkInterfaces)
| mv-expand nic=properties.networkProfile.networkInterfaces
| where nics == 1 or nic.properties.primary =~ ‘true’ or isempty(nic)
| project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id)
| join kind=leftouter (
Resources
| where type =~ ‘microsoft.network/networkinterfaces’
| extend ipConfigsCount=array_length(properties.ipConfigurations)
| mv-expand ipconfig=properties.ipConfigurations
| where ipConfigsCount == 1 or ipconfig.properties.primary =~ ‘true’
| project nicId = id, publicIpId = tostring(ipconfig.properties.publicIPAddress.id))
on nicId
| project-away nicId1
| summarize by vmId, vmName, vmSize, nicId, publicIpId
| join kind=leftouter (
Resources
| where type =~ ‘microsoft.network/publicipaddresses’
| project publicIpId = id, publicIpAddress = properties.ipAddress)
on publicIpId
| project-away publicIpId1

More information about Microsoft Azure Resource Graph Explorer

Conclusion

When you are the Microsoft Azure Administrator, the Resource Graph Explorer can be really Powerful and fast to get the right information you are looking for. When you invest in the kusto queries your can save them and Share with your Colleagues to serve your business needs. Hope this is useful for you and happy Scripting with Kusto, Powershell or Azure CLI in the Cloud

Author: James van den Berg

I'm Microsoft Architect and ICT Specialist and Microsoft MVP Cloud and Datacenter Management Microsoft MVP Windows Insider Microsoft Tech Community Insider Microsoft Azure Advisor

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 )

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.