Powershell获取特定VM的私有IP
Powershell to get private IP of specific VM
我正在尝试获取特定 VM 的专用 IP。我有这个有效的代码
$vms = get-azurermvm -ResourceGroupName abc
$nics = get-azurermnetworkinterface -ResourceGroupName abc| where VirtualMachine -NE $null #skip Nics with no VM
foreach($nic in $nics)
{
$vm = $vms | where-object -Property Id -EQ $nic.VirtualMachine.id
$prv = $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAddress
Write-Output "$($vm.Name) : $prv"
}
我有名称为 es-client-node1
、es-client-node2
、es-master-node1
、es-data-node1
和 es-data-node1
的虚拟机。我想获取客户端节点的 IP 地址或 VM 的名称与 es-client-node*
匹配,同样对于数据节点和主节点到不同的变量
知道如何在 powershell 中执行此操作吗?
要使用 PowerShell 获取私有 IP,您可以使用此命令:
$IP = (Get-AzureRmNetworkInterface -Name $VMName -ResourceGroupName $RGName).IpConfigurations.PrivateIpAddress
az network nic list --query '[*].{Name:name,PrivateIpAddress:ipConfigurations[0].privateIpAddress,ResourceGroup:resourceGroup}'
我正在尝试获取特定 VM 的专用 IP。我有这个有效的代码
$vms = get-azurermvm -ResourceGroupName abc
$nics = get-azurermnetworkinterface -ResourceGroupName abc| where VirtualMachine -NE $null #skip Nics with no VM
foreach($nic in $nics)
{
$vm = $vms | where-object -Property Id -EQ $nic.VirtualMachine.id
$prv = $nic.IpConfigurations | select-object -ExpandProperty PrivateIpAddress
Write-Output "$($vm.Name) : $prv"
}
我有名称为 es-client-node1
、es-client-node2
、es-master-node1
、es-data-node1
和 es-data-node1
的虚拟机。我想获取客户端节点的 IP 地址或 VM 的名称与 es-client-node*
匹配,同样对于数据节点和主节点到不同的变量
知道如何在 powershell 中执行此操作吗?
要使用 PowerShell 获取私有 IP,您可以使用此命令:
$IP = (Get-AzureRmNetworkInterface -Name $VMName -ResourceGroupName $RGName).IpConfigurations.PrivateIpAddress
az network nic list --query '[*].{Name:name,PrivateIpAddress:ipConfigurations[0].privateIpAddress,ResourceGroup:resourceGroup}'