@@ -11,7 +11,7 @@ Note that when using Resource Graph Explorer, you will ONLY be able to see the s
11
11
```
12
12
ResourceContainers
13
13
| where type =~ 'microsoft.resources/subscriptions'
14
- | project SubName =name, subscriptionId
14
+ | project subscriptionName =name, subscriptionId
15
15
```
16
16
17
17
### LIST ALL VMs (simple) ###
@@ -23,6 +23,18 @@ Resources
23
23
| limit 25
24
24
```
25
25
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
+
26
38
### List VMs with detail (excluding IP info)
27
39
```
28
40
Resources
@@ -44,10 +56,11 @@ Resources
44
56
| where type == "microsoft.compute/virtualmachines" and isnotempty(properties.networkProfile.networkInterfaces)
45
57
| extend vmSize = tostring(properties.hardwareProfile.vmSize)
46
58
| extend osType = tostring(properties.storageProfile.osDisk.osType)
47
- | extend nicId = tostring(properties.networkProfile.networkInterfaces[0].id)
48
59
| extend vmProperties = tostring(properties)
60
+ | mv-expand nics = properties.networkProfile.networkInterfaces
61
+ | extend nicId = tostring(nics.id)
49
62
| join kind=leftouter (Resources
50
- | where type =~ "microsoft.network/networkinterfaces"
63
+ | where type =~ "microsoft.network/networkinterfaces"
51
64
| extend privateIP = tostring(properties.ipConfigurations[0].properties["privateIPAddress"])
52
65
| extend pubId = tostring(properties.ipConfigurations[0].properties.publicIPAddress.id)
53
66
| extend subnetId = tostring(properties.ipConfigurations[0].properties.subnet.id)
@@ -58,7 +71,24 @@ Resources
58
71
| project nicId=id, nicName=name, privateIP, publicIP, fqdn, pubId, nicProperties=properties, pubIpProperties) on nicId
59
72
| join kind=leftouter (ResourceContainers | where type=~'microsoft.resources/subscriptions'
60
73
| 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
62
92
```
63
93
64
94
### List all NICS and the associated VM in a given subnet name
0 commit comments