Hey there! Welcome to my collection of Azure Resource Graph queries. This repo is basically my personal stash of useful KQL (Kusto Query Language) queries that I use to dig through Azure resources.
Each folder contains a KQL query along with its own README that breaks down:
- What the query actually does
- How it works step by step
- What the output looks like
- Some sample results to give you an idea
- Clone repository
git clone https://github.com/juddlestone/resource-graph-queries
- Move into the directory
cd azure-resource-graph-queries
- Install required modules
Install-Module -Name Az.ResourceGraph
- Get query of choice
$query = Get-Content -Path ".\orphaned-disks\query.kql" -Raw
- Execute query
$results = Search-AzGraph -Query $query
- Export results
$results | Export-Csv -Path ".\results.csv" -NoTypeInformation
- Amend step four to the following
$queryFiles = Get-ChildItem -Path "." -Filter "query.kql" -Recurse
- Iterate over each file
foreach ($file in $queryFiles) {
Write-Host "Running query from: $($file.FullName)"
$queryContent = Get-Content -Path $file.FullName -Raw
$results = Search-AzGraph -Query $queryContent
$outputPath = Join-Path $file.DirectoryName "results.csv"
$results | Export-Csv -Path $outputPath -NoTypeInformation
Write-Host "Results saved to: $outputPath`n"
}
- Pop open Azure Portal
- Head to Resource Graph Explorer
- Copy & paste any query you fancy
- Hit run and see what you find!