gpt4 book ai didi

azure - 打印子网中的所有虚拟机名称和私有(private) IP

转载 作者:行者123 更新时间:2023-12-03 05:27:32 25 4
gpt4 key购买 nike

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

我希望 Azure Resource Graph Explorer 中的此查询至少能打印所有非空私有(private) IP 地址:

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

最佳答案

您需要查看网络接口(interface)并展开属性以提取专用 IP 地址。像这样的事情应该可以解决问题。我修改了我们的一个examples拉取私有(private)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

关于azure - 打印子网中的所有虚拟机名称和私有(private) IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67674782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com