2016-09-21 87 views
0

我正在尝试获取特定VM的私有IP。我有这样的代码这是工作Powershell获取特定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" 
} 

我的VM名es-client-node1es-client-node2es-master-node1es-data-node1 & es-data-node1。我想获得只是客户端节点的IP地址或虚拟机的名称匹配es-client-node*,类似于datanode &主节点到不同的变量

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

回答

2

为了得到使用PowerShell私有IP,你可以使用这个命令 -

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

我希望这适合于你想达到的目标。