@@ -251,6 +251,29 @@ Resources
251
251
| project subscriptionName, name, resourceGroup, location, ipCount, privateIPType, privateIP, publicIP, nicNSG, resourceGroupNSG, tags, subnetId, nicId
252
252
```
253
253
254
+ ### List all NSG security rules in one query
255
+ Courtesy of https://blog.blksthl.com/2020/10/02/list-all-nsg-security-rules-in-one-query-using-azure-resource-graph/
256
+
257
+ ```
258
+ Resources
259
+ | where type =~ "microsoft.network/networksecuritygroups"
260
+ | join kind=leftouter (ResourceContainers | where type=='microsoft.resources/subscriptions' | project SubcriptionName=name, subscriptionId) on subscriptionId
261
+ | where resourceGroup == 'production' or resourceGroup == 'testing'
262
+ // Only if you don't want to see all, add more resourceGroups as needed: or resourceGroup == 'xxx'
263
+ | mv-expand rules=properties.securityRules
264
+ | extend direction = tostring(rules.properties.direction)
265
+ | extend priority = toint(rules.properties.priority)
266
+ | extend description = rules.properties.description
267
+ | extend destprefix = rules.properties.destinationAddressPrefix
268
+ | extend destport = rules.properties.destinationPortRange
269
+ | extend sourceprefix = rules.properties.sourceAddressPrefix
270
+ | extend sourceport = rules.properties.sourcePortRange
271
+ | extend subnet_name = split((split(tostring(properties.subnets), '/'))[10], '"')[0]
272
+ //| where destprefix == '*'
273
+ | project SubcriptionName, resourceGroup, subnet_name, name, direction, priority, destprefix, destport, sourceprefix, sourceport, description //, subscriptionId, rules.properties
274
+ | sort by SubcriptionName, resourceGroup asc, name, direction asc, priority asc
275
+ ```
276
+
254
277
255
278
### List all Network Interfaces (NICs) with NSG detail
256
279
This lists all NICs with the associated NSG, subnet, subnet NSG,
0 commit comments