Skip to content

Commit 85c0ae0

Browse files
committed
Update Kusto Graph Explorer Queries.md
1 parent 24d77cd commit 85c0ae0

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

AZURE/Kusto Graph Explorer Queries.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Note that when using Resource Graph Explorer, you will ONLY be able to see the s
1111
```
1212
ResourceContainers
1313
| where type =~ 'microsoft.resources/subscriptions'
14-
| project SubName=name, subscriptionId
14+
| project subscriptionName=name, subscriptionId
1515
```
1616

1717
### LIST ALL VMs (simple) ###
@@ -23,6 +23,18 @@ Resources
2323
| limit 25
2424
```
2525

26+
### List all VMs with names that might indicate a database is present
27+
```
28+
resources
29+
| where type == "microsoft.compute/virtualmachines"
30+
and (name contains "sql"
31+
or name contains "db"
32+
or name contains "database")
33+
| join kind=leftouter (ResourceContainers | where type=~ 'microsoft.resources/subscriptions'
34+
| project subscriptionName=name, subscriptionId) on subscriptionId
35+
| project subscriptionId, subscriptionName, name, resourceGroup, location, properties, tags, id
36+
```
37+
2638
### List VMs with detail (excluding IP info)
2739
```
2840
Resources
@@ -44,10 +56,11 @@ Resources
4456
| where type == "microsoft.compute/virtualmachines" and isnotempty(properties.networkProfile.networkInterfaces)
4557
| extend vmSize = tostring(properties.hardwareProfile.vmSize)
4658
| extend osType = tostring(properties.storageProfile.osDisk.osType)
47-
| extend nicId = tostring(properties.networkProfile.networkInterfaces[0].id)
4859
| extend vmProperties = tostring(properties)
60+
| mv-expand nics = properties.networkProfile.networkInterfaces
61+
| extend nicId = tostring(nics.id)
4962
| join kind=leftouter (Resources
50-
| where type =~ "microsoft.network/networkinterfaces"
63+
| where type =~ "microsoft.network/networkinterfaces"
5164
| extend privateIP = tostring(properties.ipConfigurations[0].properties["privateIPAddress"])
5265
| extend pubId = tostring(properties.ipConfigurations[0].properties.publicIPAddress.id)
5366
| extend subnetId = tostring(properties.ipConfigurations[0].properties.subnet.id)
@@ -58,7 +71,24 @@ Resources
5871
| project nicId=id, nicName=name, privateIP, publicIP, fqdn, pubId, nicProperties=properties, pubIpProperties) on nicId
5972
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
6073
| project subscriptionName=name, subscriptionId) on subscriptionId
61-
| project name, resourceGroup, subscriptionName, location, osType, vmSize, nicName, privateIP, publicIP, fqdn, nicProperties, pubIpProperties, vmProperties, id
74+
| project name, resourceGroup, subscriptionName, location, osType, vmSize, nicName, privateIP, publicIP, fqdn, nicProperties, pubIpProperties, vmProperties, nicId, id
75+
```
76+
77+
### List NSGs by Inbound Destinations and Ports
78+
Excludes defaultSecurityRules.
79+
80+
```
81+
resources
82+
| where type =~ "microsoft.network/networksecuritygroups"
83+
| mv-expand rule = properties.securityRules
84+
| where rule.properties.access =~ "Allow" and rule.properties.direction =~ "Inbound"
85+
| extend ruleName = rule.name,
86+
priority = rule.properties.priority,
87+
dstAddressPrefix = rule.properties.destinationAddressPrefix,
88+
dstAddresses = rule.properties.destinationAddressPrefixes,
89+
dstPortRange = rule.properties.destinationPortRange,
90+
dstPortRanges = rule.properties.destinationPortRanges
91+
| project name, resourceGroup, location, subscriptionId, priority, dstAddressPrefix, dstAddresses, dstPortRange, dstPortRanges, rule, properties, tags
6292
```
6393

6494
### List all NICS and the associated VM in a given subnet name

0 commit comments

Comments
 (0)