1
1
# Kusto Graph Explorer Queries
2
2
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 .
4
5
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.
5
9
6
10
### LIST ALL SUBSCRIPTIONS ###
7
11
```
@@ -57,6 +61,25 @@ Resources
57
61
| project name, resourceGroup, subscriptionName, location, osType, vmSize, nicName, privateIP, publicIP, fqdn, nicProperties, pubIpProperties, vmProperties, id
58
62
```
59
63
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
+ ```
60
83
61
84
### LIST ALL NICs with Public and Private IP addresses abd FQDNs
62
85
Note that resource graph is NOT always up to date with dynamically assigned public IP addresses.
@@ -75,9 +98,10 @@ Resources
75
98
| project nicId=id, nicName=name, privateIP, publicIP, fqdn, pubId, pubIpProperties
76
99
```
77
100
78
- ### List all NICs with the associuated VMs
101
+ ### List all NICs with the associated VMs
79
102
TO DO.
80
103
104
+
81
105
### List all devices with 2 or more IP addresses
82
106
```
83
107
Resources
@@ -119,7 +143,6 @@ Resources
119
143
```
120
144
121
145
122
-
123
146
### Splits IP configurations into a single row per entry
124
147
```
125
148
Resources
@@ -129,31 +152,66 @@ Resources
129
152
130
153
131
154
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
+
133
158
```
134
159
Resources
135
160
| where type =~ "microsoft.network/networkinterfaces" and isnotempty(properties.ipConfigurations)
136
161
| 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
141
171
| 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
144
188
```
145
189
146
190
### 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"
149
195
| extend networkProfile = tostring(properties.networkProfile)
150
196
| extend computerName = properties.osProfile.computerName
151
197
| 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
+ ```
153
202
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
+ ```
154
211
155
212
156
213
### List Azure Bastion Hosts with IP Addresses
214
+
157
215
```
158
216
Resources
159
217
| where type =~ "microsoft.network/networkinterfaces" and isnotempty(properties.ipConfigurations)
@@ -174,6 +232,7 @@ Resources
174
232
175
233
### List Virtuan Networks (VNets) with IP addresses
176
234
This is crude as I need to way to count and join all instances
235
+
177
236
```
178
237
Resources
179
238
| where type =~ "microsoft.network/virtualnetworks"
0 commit comments