Skip to content

Commit 3ec0403

Browse files
committed
Update Kusto Graph Explorer Queries.md
1 parent 35467a4 commit 3ec0403

File tree

1 file changed

+72
-13
lines changed

1 file changed

+72
-13
lines changed

AZURE/Kusto Graph Explorer Queries.md

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Kusto Graph Explorer Queries
22
The Resource Graph queries can be done through PowerShell or via the Azure Portal under "Resource Graph Explorer".
3-
See also: https://docs.microsoft.com/en-us/azure/governance/resource-graph/samples/starter?tabs=azure-cli
3+
See also: https://docs.microsoft.com/en-us/azure/governance/resource-graph/samples/starter?tabs=azure-cli and
4+
https://docs.microsoft.com/en-us/azure/governance/resource-graph/samples/advanced?tabs=azure-cli.
45

6+
These queries may be pasted into the Azure Resource Graph Explorer or used via **Search-AzGraph -Query $Query**.
7+
Note that when using Resource Graph Explorer, you will ONLY be able to see the subscriptions for which:
8+
(a) you have permission; and (b) which are selected in your global subscriptions filter.
59

610
### LIST ALL SUBSCRIPTIONS ###
711
```
@@ -57,6 +61,25 @@ Resources
5761
| project name, resourceGroup, subscriptionName, location, osType, vmSize, nicName, privateIP, publicIP, fqdn, nicProperties, pubIpProperties, vmProperties, id
5862
```
5963

64+
### List all NICS and the associated VM in a given subnet name
65+
To Do: Output the VNET and subnet and privateIP as well.
66+
67+
```
68+
Resources
69+
| where type =~ "microsoft.network/networkinterfaces" and (tostring(properties) contains 'azsu-subn-devtest-h-web-bsmart-001')
70+
| extend subnets = tostring(properties["subnets"])
71+
| extend prefixCount = array_length(properties.subnets)
72+
| extend nicName = name
73+
| extend nicId = id
74+
| join kind=leftouter (Resources
75+
| where type =~ "microsoft.compute/virtualmachines"
76+
| extend nicId = tostring(properties.networkProfile.networkInterfaces[0].id)
77+
| project VmName=name, vmId=id, vmProperties=properties, nicId) on nicId
78+
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
79+
| project subscriptionName=name, subscriptionId) on subscriptionId
80+
| project VmName, resourceGroup, subscriptionName, location, nicName, properties
81+
82+
```
6083

6184
### LIST ALL NICs with Public and Private IP addresses abd FQDNs
6285
Note that resource graph is NOT always up to date with dynamically assigned public IP addresses.
@@ -75,9 +98,10 @@ Resources
7598
| project nicId=id, nicName=name, privateIP, publicIP, fqdn, pubId, pubIpProperties
7699
```
77100

78-
### List all NICs with the associuated VMs
101+
### List all NICs with the associated VMs
79102
TO DO.
80103

104+
81105
### List all devices with 2 or more IP addresses
82106
```
83107
Resources
@@ -119,7 +143,6 @@ Resources
119143
```
120144

121145

122-
123146
### Splits IP configurations into a single row per entry
124147
```
125148
Resources
@@ -129,31 +152,66 @@ Resources
129152

130153

131154

132-
### Find Resource by IP address
155+
### Find NIC by private IP address
156+
This outputs the vmName, resourceGroup, subscriptionName, location, privateIP, privateIPType, publicIP, vnetName, subnetName, vmId, and subnetId.
157+
133158
```
134159
Resources
135160
| where type =~ "microsoft.network/networkinterfaces" and isnotempty(properties.ipConfigurations)
136161
| mv-expand ipConfiguration = properties.ipConfigurations
137-
| where ipConfiguration.properties.privateIPAddress =~ "10.64.193.86"
138-
| extend privateIPType = tostring(ipConfiguration.properties.privateIPAllocationMethod)
139-
| extend privateIP = tostring(ipConfiguration.properties.privateIPAddress)
140-
| extend publicIPid = tostring(ipConfiguration.properties.publicIPAddress.id)
162+
| where ipConfiguration.properties.privateIPAddress == "10.65.96.6" or ipConfiguration.properties.privateIPAddress == "10.65.105.100"
163+
| extend
164+
privateIPType = tostring(ipConfiguration.properties.privateIPAllocationMethod),
165+
privateIP = tostring(ipConfiguration.properties.privateIPAddress),
166+
publicIPid = tostring(ipConfiguration.properties.publicIPAddress.id),
167+
subnetId = tostring(ipConfiguration.properties.subnet.id),
168+
vnetName = tostring(split(ipConfiguration.properties.subnet.id,'/',8)[0]),
169+
subnetName = tostring(split(ipConfiguration.properties.subnet.id,'/',10)[0]),
170+
nicId = id
141171
| join kind=leftouter (Resources | where type =~ "microsoft.network/publicipaddresses"
142-
| extend publicIPaddr = tostring(properties.ipAddress)
143-
| project publicIPid=id, publicIPaddr) on publicIPid
172+
| extend publicIP = tostring(properties.ipAddress)
173+
| project publicIPid=id, publicIP) on publicIPid
174+
| join kind=leftouter (Resources
175+
| where type =~ "microsoft.compute/virtualmachines"
176+
| extend
177+
networkProfile = tostring(properties.networkProfile),
178+
computerName = properties.osProfile.computerName
179+
| mv-expand networkInterfaces = properties.networkProfile.networkInterfaces
180+
| extend
181+
nicId = tostring(networkInterfaces.id),
182+
vmName = name,
183+
vmId = id
184+
| project vmName, nicId, vmId) on nicId
185+
| join kind=leftouter (ResourceContainers | where type=~"microsoft.resources/subscriptions"
186+
| project subscriptionName=name, subscriptionId) on subscriptionId
187+
| project vmName, resourceGroup, subscriptionName, location, privateIP, privateIPType, publicIP, vnetName, subnetName, vmId, subnetId
144188
```
145189

146190
### Find VM given its network interface ID
147-
$KustoFindVMbyInterfaceID = 'Resources
148-
| where type =~ "microsoft.compute/virtualmachines"
191+
192+
```
193+
Resources
194+
| where type =~ "microsoft.compute/virtualmachines"
149195
| extend networkProfile = tostring(properties.networkProfile)
150196
| extend computerName = properties.osProfile.computerName
151197
| mv-expand networkInterfaces = properties.networkProfile.networkInterfaces
152-
| where networkInterfaces.id =~ "%%ID%%"'
198+
| where networkInterfaces.id =~ "%%ID%%"
199+
| join kind=leftouter (ResourceContainers | where type=~"microsoft.resources/subscriptions"
200+
| project subscriptionName=name, subscriptionId) on subscriptionId
201+
```
153202

203+
### List all Resources (or ResourceContainers) without a given tag
204+
205+
```
206+
resources
207+
| where properties.provisioningState =~ "Succeeded" and tostring(tags) !contains '"CreatedBy"'
208+
| join kind=leftouter (ResourceContainers | where type =~ 'microsoft.resources/subscriptions'
209+
| project subscriptionName=name, subscriptionId) on subscriptionId
210+
```
154211

155212

156213
### List Azure Bastion Hosts with IP Addresses
214+
157215
```
158216
Resources
159217
| where type =~ "microsoft.network/networkinterfaces" and isnotempty(properties.ipConfigurations)
@@ -174,6 +232,7 @@ Resources
174232

175233
### List Virtuan Networks (VNets) with IP addresses
176234
This is crude as I need to way to count and join all instances
235+
177236
```
178237
Resources
179238
| where type =~ "microsoft.network/virtualnetworks"

0 commit comments

Comments
 (0)