Skip to content

Commit a6e92d9

Browse files
committed
Update Kusto Graph Explorer Queries.md
1 parent fa5ae18 commit a6e92d9

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

AZURE/Kusto Graph Explorer Queries.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ Resources
2222
```
2323
Resources
2424
| where type =~ 'Microsoft.Compute/virtualMachines'
25+
| extend ServiceOwner = tostring(tags['Service Owner'])
26+
| extend ServiceName = tostring(tags['Service Name'])
27+
| extend CostCodeID = tostring(tags['Cost Code ID'])
2528
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
2629
| project SubName=name, subscriptionId) on subscriptionId
2730
| project subscriptionId, name, resourceGroup, location,
2831
vmSize = tostring(properties.hardwareProfile.vmSize),
2932
osType = tostring(properties.storageProfile.osDisk.osType),
30-
hostId = tostring(properties.host.id), tags, id
33+
hostId = tostring(properties.host.id), tags, id,
34+
ServiceOwner,ServiceName,CostCodeID
3135
```
3236

3337

@@ -303,6 +307,37 @@ Do
303307
Until ($r.Count -lt 1000)
304308
```
305309

310+
## List all Resource Groups with Subordinate Cost Code ID
311+
```
312+
resourcecontainers
313+
| where type == "microsoft.resources/subscriptions/resourcegroups"
314+
| extend ServiceOwner = tostring(tags["Service Owner"])
315+
| extend ServiceName = tostring(tags["Service Name"])
316+
| extend CostCodeID = tostring(tags["Cost Code ID"])
317+
| join kind=inner (Resources | where tags contains "Cost Code ID" | extend SubCostCodeID = tostring(tags["Cost Code ID"]) | project resourceGroup,SubordinateTags=tags,SubCostCodeID) on resourceGroup
318+
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
319+
| project SubName=name, subscriptionId) on subscriptionId
320+
| project subscriptionId, SubName, resourceGroup, location, CostCodeID, ServiceOwner, ServiceName, tags,SubordinateTags, SubCostCodeID
321+
```
322+
323+
## List all Resources WITHOUT 'Cost Code ID' tag
324+
```
325+
Resources
326+
| where tags !contains "Cost Code ID"
327+
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
328+
| project SubName=name, subscriptionId) on subscriptionId
329+
| project subscriptionId, SubName, name, resourceGroup, location, tags, type
330+
```
331+
332+
333+
---
334+
## Using PowerShell
335+
336+
```
337+
$q = "YOUR_KUSTO_QUERY"
338+
$Results = Search-AzGraph -query $q -First 5000 ; write-host "$($Results.Count) entries"
339+
$Results | Out-GridView # Or Export-CSV
340+
```
306341

307342
---
308343
## References

0 commit comments

Comments
 (0)