Skip to content

Commit 0d81d8b

Browse files
committed
Update Kusto Graph Explorer Queries.md
1 parent 9573ac9 commit 0d81d8b

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

AZURE/Kusto Graph Explorer Queries.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ These queries may be pasted into the Azure Resource Graph Explorer or used via *
77
Note that when using Resource Graph Explorer, you will ONLY be able to see the subscriptions for which:
88
(a) you have permission; and (b) which are selected in your global subscriptions filter.
99

10+
To invoke a Kusto Query in PowerShell:
11+
12+
```Search-AzGraph -First 1000 -Query $Query```
13+
14+
1015
#### Additional Resources
1116

1217
* https://github.com/kobusd/Azure-Resource-Graph
@@ -196,7 +201,11 @@ Resources
196201
### List all Network Interfaces (NICs) with NSG detail
197202
This lists all NICs with the associated NSG, subnet, subnet NSG,
198203
and their public and private IP addresses. Very use for seeing which VMs
199-
are protected ny an NSG and which are not.
204+
are protected by an NSG and which are not.
205+
206+
NOTE: This only works in the Azure ARM Portal. To use in PowerShell, you MUST ask Microsoft
207+
to increase your mv-expand and join limits!
208+
200209

201210
```
202211
Resources
@@ -208,30 +217,30 @@ Resources
208217
| extend subnetId = tostring(ipConfigurations.properties.subnet["id"])
209218
| extend publicIPid = tostring(ipConfigurations.properties["publicIPAddress"].id)
210219
| extend nicId = tostring(id)
211-
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
220+
| join kind=leftouter (ResourceContainers | where type=~ "microsoft.resources/subscriptions"
212221
| project subscriptionName=name, subscriptionId) on subscriptionId
213222
| join kind=leftouter (Resources
214-
| where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress)
223+
| where type contains "publicIPAddresses" and isnotempty(properties.ipAddress)
215224
| extend publicIP = tostring(properties.ipAddress),
216225
publicIPid = tostring(id)) on publicIPid
217-
| join kind=leftouter (Resources | where type == "microsoft.network/networksecuritygroups"
226+
| join kind=leftouter (Resources | where type =~ "microsoft.network/networksecuritygroups"
218227
| mv-expand nics = properties.networkInterfaces
219228
| extend nicId = tostring (nics.id),
220229
nicNSG = name,
221230
nicNSGgroup = resourceGroup ) on nicId
222-
| join kind=leftouter (Resources | where type == "microsoft.network/networksecuritygroups"
231+
| join kind=leftouter (Resources | where type =~ "microsoft.network/networksecuritygroups"
223232
| mv-expand subnets = properties.subnets
224233
| extend subnetId = tostring(subnets.id),
225-
vnetName = split(tostring(subnets.id),'/')[8],
226-
subnetName = split(tostring(subnets.id),'/')[10],
234+
vnetName = split(tostring(subnets.id),"/")[8],
235+
subnetName = split(tostring(subnets.id),"/")[10],
227236
subnetNSG = name,
228237
subnetNSGgroup = resourceGroup
229238
) on subnetId
230239
| project subscriptionName, nicName=name, resourceGroup, vnetName, subnetName, nicNSG, subnetNSG, location, ipCount, privateIPType, privateIP, publicIP, tags, subnetId, nicId
231240
```
232241

233-
As there is a limit of four (4) joins ina kusto resource graph query, we can either return the subscription name or the associated VM name.
234-
The query below lists all wit VM name but without subscription name.
242+
The query below lists all with VM name with subscription name.
243+
This query requires a quota increase from Microsoft.
235244

236245
```
237246
Resources
@@ -243,31 +252,33 @@ Resources
243252
| extend subnetId = tostring(ipConfigurations.properties.subnet["id"])
244253
| extend publicIPid = tostring(ipConfigurations.properties["publicIPAddress"].id)
245254
| extend nicId = tostring(id)
255+
| join kind=leftouter (ResourceContainers | where type=~ "microsoft.resources/subscriptions"
256+
| project subscriptionName=name, subscriptionId) on subscriptionId
246257
| join kind=leftouter (Resources
247-
| where type contains 'publicIPAddresses' and isnotempty(properties.ipAddress)
258+
| where type contains "publicIPAddresses" and isnotempty(properties.ipAddress)
248259
| extend publicIP = tostring(properties.ipAddress),
249260
publicIPid = tostring(id)) on publicIPid
250-
| join kind=leftouter (Resources | where type == "microsoft.network/networksecuritygroups"
261+
| join kind=leftouter (Resources | where type =~ "microsoft.network/networksecuritygroups"
251262
| mv-expand nics = properties.networkInterfaces
252263
| extend nicId = tostring (nics.id),
253264
nicNSG = name,
254265
nicNSGgroup = resourceGroup ) on nicId
255266
| join kind=leftouter (Resources
256-
| where type == "microsoft.compute/virtualmachines" and isnotempty(properties.networkProfile.networkInterfaces)
267+
| where type =~ "microsoft.compute/virtualmachines" and isnotempty(properties.networkProfile.networkInterfaces)
257268
| extend vmName = name
258269
| extend vmSize = tostring(properties.hardwareProfile.vmSize)
259270
| extend osType = tostring(properties.storageProfile.osDisk.osType)
260271
| mv-expand nics = properties.networkProfile.networkInterfaces
261272
| extend nicId = tostring (nics.id) ) on nicId
262-
| join kind=leftouter (Resources | where type == "microsoft.network/networksecuritygroups"
273+
| join kind=leftouter (Resources | where type =~ "microsoft.network/networksecuritygroups"
263274
| mv-expand subnets = properties.subnets
264275
| extend subnetId = tostring(subnets.id),
265-
vnetName = split(tostring(subnets.id),'/')[8],
266-
subnetName = split(tostring(subnets.id),'/')[10],
276+
vnetName = split(tostring(subnets.id),"/")[8],
277+
subnetName = split(tostring(subnets.id),"/")[10],
267278
subnetNSG = name,
268279
subnetNSGgroup = resourceGroup
269280
) on subnetId
270-
| project subscriptionId, nicName=name, resourceGroup, vmName, vmSize, osType, vnetName, subnetName, nicNSG, subnetNSG, location, ipCount, privateIPType, privateIP, publicIP, tags, subnetId, nicId
281+
| project subscriptionId, subscriptionName, nicName=name, resourceGroup, vmName, vmSize, osType, vnetName, subnetName, nicNSG, subnetNSG, location, ipCount, privateIPType, privateIP, publicIP, tags, subnetId, nicId
271282
```
272283

273284

0 commit comments

Comments
 (0)