@@ -7,6 +7,11 @@ These queries may be pasted into the Azure Resource Graph Explorer or used via *
7
7
Note that when using Resource Graph Explorer, you will ONLY be able to see the subscriptions for which:
8
8
(a) you have permission; and (b) which are selected in your global subscriptions filter.
9
9
10
+ To invoke a Kusto Query in PowerShell:
11
+
12
+ ``` Search-AzGraph -First 1000 -Query $Query ```
13
+
14
+
10
15
#### Additional Resources
11
16
12
17
* https://github.com/kobusd/Azure-Resource-Graph
@@ -196,7 +201,11 @@ Resources
196
201
### List all Network Interfaces (NICs) with NSG detail
197
202
This lists all NICs with the associated NSG, subnet, subnet NSG,
198
203
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
+
200
209
201
210
```
202
211
Resources
@@ -208,30 +217,30 @@ Resources
208
217
| extend subnetId = tostring(ipConfigurations.properties.subnet["id"])
209
218
| extend publicIPid = tostring(ipConfigurations.properties["publicIPAddress"].id)
210
219
| extend nicId = tostring(id)
211
- | join kind=leftouter (ResourceContainers | where type=~' microsoft.resources/subscriptions'
220
+ | join kind=leftouter (ResourceContainers | where type=~ " microsoft.resources/subscriptions"
212
221
| project subscriptionName=name, subscriptionId) on subscriptionId
213
222
| join kind=leftouter (Resources
214
- | where type contains ' publicIPAddresses' and isnotempty(properties.ipAddress)
223
+ | where type contains " publicIPAddresses" and isnotempty(properties.ipAddress)
215
224
| extend publicIP = tostring(properties.ipAddress),
216
225
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"
218
227
| mv-expand nics = properties.networkInterfaces
219
228
| extend nicId = tostring (nics.id),
220
229
nicNSG = name,
221
230
nicNSGgroup = resourceGroup ) on nicId
222
- | join kind=leftouter (Resources | where type == "microsoft.network/networksecuritygroups"
231
+ | join kind=leftouter (Resources | where type =~ "microsoft.network/networksecuritygroups"
223
232
| mv-expand subnets = properties.subnets
224
233
| 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],
227
236
subnetNSG = name,
228
237
subnetNSGgroup = resourceGroup
229
238
) on subnetId
230
239
| project subscriptionName, nicName=name, resourceGroup, vnetName, subnetName, nicNSG, subnetNSG, location, ipCount, privateIPType, privateIP, publicIP, tags, subnetId, nicId
231
240
```
232
241
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 .
235
244
236
245
```
237
246
Resources
@@ -243,31 +252,33 @@ Resources
243
252
| extend subnetId = tostring(ipConfigurations.properties.subnet["id"])
244
253
| extend publicIPid = tostring(ipConfigurations.properties["publicIPAddress"].id)
245
254
| extend nicId = tostring(id)
255
+ | join kind=leftouter (ResourceContainers | where type=~ "microsoft.resources/subscriptions"
256
+ | project subscriptionName=name, subscriptionId) on subscriptionId
246
257
| join kind=leftouter (Resources
247
- | where type contains ' publicIPAddresses' and isnotempty(properties.ipAddress)
258
+ | where type contains " publicIPAddresses" and isnotempty(properties.ipAddress)
248
259
| extend publicIP = tostring(properties.ipAddress),
249
260
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"
251
262
| mv-expand nics = properties.networkInterfaces
252
263
| extend nicId = tostring (nics.id),
253
264
nicNSG = name,
254
265
nicNSGgroup = resourceGroup ) on nicId
255
266
| 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)
257
268
| extend vmName = name
258
269
| extend vmSize = tostring(properties.hardwareProfile.vmSize)
259
270
| extend osType = tostring(properties.storageProfile.osDisk.osType)
260
271
| mv-expand nics = properties.networkProfile.networkInterfaces
261
272
| 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"
263
274
| mv-expand subnets = properties.subnets
264
275
| 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],
267
278
subnetNSG = name,
268
279
subnetNSGgroup = resourceGroup
269
280
) 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
271
282
```
272
283
273
284
0 commit comments