Powershell获取特定VM的私有IP

时间:2016-09-21 19:09:45

标签: powershell azure powershell-v4.0 azure-automation

我正在尝试获取特定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-node1es-client-node2es-master-node1es-data-node1& es-data-node1。我想得到客户端节点的IP地址或VM的名称与es-client-node*匹配,类似于datanode&主节点进入不同的变量

任何想法如何在powershell中做到这一点?

1 个答案:

答案 0 :(得分:5)

要使用PowerShell获取私有IP,您可以使用此命令 -

$IP = (Get-AzureRmNetworkInterface -Name $VMName -ResourceGroupName $RGName).IpConfigurations.PrivateIpAddress

我希望这适合你想要实现的目标。

相关问题