2016-09-21 34 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 

我希望這適合於你想達到的目標。