从子网打印所有 VM 名称和专用 IP
Print all VM names and private IP from subnet
我想列出特定子网下所有包含私有 IP 地址的虚拟机名称(例如,名为“sub-a”)。我该怎么做?
我希望 Azure Resource Graph Explorer 中的这个查询至少会打印所有非空的私有 IP 地址:
Resources
| where type =~ 'microsoft.compute/virtualmachines' and isnotempty(properties.privateIPAddress)
您需要查看网络接口并展开属性以提取专用 IP 地址。这样的事情应该可以解决问题。我修改了我们的一个 examples 来提取私有 IP 而不是 public IP。
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| extend nics=array_length(properties.networkProfile.networkInterfaces)
| mv-expand nic=properties.networkProfile.networkInterfaces
| where nics == 1 or nic.properties.primary =~ 'true' or isempty(nic)
| project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id)
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/networkinterfaces'
| extend ipConfigsCount=array_length(properties.ipConfigurations)
| extend subnet = tostring(properties.ipConfigurations[0].properties.subnet)
| mv-expand ipconfig=properties.ipConfigurations
| where ipConfigsCount == 1 or ipconfig.properties.primary =~ 'true'
| project nicId = id, subnet, privateIp = tostring(ipconfig.properties.privateIPAddress))
on nicId
| order by subnet asc
我想列出特定子网下所有包含私有 IP 地址的虚拟机名称(例如,名为“sub-a”)。我该怎么做?
我希望 Azure Resource Graph Explorer 中的这个查询至少会打印所有非空的私有 IP 地址:
Resources
| where type =~ 'microsoft.compute/virtualmachines' and isnotempty(properties.privateIPAddress)
您需要查看网络接口并展开属性以提取专用 IP 地址。这样的事情应该可以解决问题。我修改了我们的一个 examples 来提取私有 IP 而不是 public IP。
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| extend nics=array_length(properties.networkProfile.networkInterfaces)
| mv-expand nic=properties.networkProfile.networkInterfaces
| where nics == 1 or nic.properties.primary =~ 'true' or isempty(nic)
| project vmId = id, vmName = name, vmSize=tostring(properties.hardwareProfile.vmSize), nicId = tostring(nic.id)
| join kind=leftouter (
Resources
| where type =~ 'microsoft.network/networkinterfaces'
| extend ipConfigsCount=array_length(properties.ipConfigurations)
| extend subnet = tostring(properties.ipConfigurations[0].properties.subnet)
| mv-expand ipconfig=properties.ipConfigurations
| where ipConfigsCount == 1 or ipconfig.properties.primary =~ 'true'
| project nicId = id, subnet, privateIp = tostring(ipconfig.properties.privateIPAddress))
on nicId
| order by subnet asc