0

我想列出所有在特定子网下包含私有 IP 地址的虚拟机名称(例如,名为“sub-a”)。我怎么做?

我希望 Azure Resource Graph Explorer 中的这个查询至少能打印出所有非空的私有 IP 地址:

Resources
| where type =~ 'microsoft.compute/virtualmachines' and isnotempty(properties.privateIPAddress)
4

1 回答 1

2

您需要查看网络接口并展开属性以提取私有 IP 地址。像这样的东西应该可以解决问题。我修改了我们的一个示例以提取私有 IP 而不是公共 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
于 2021-05-24T18:19:44.123 回答