Reputation: 7068
I am trying to get private IP of specific VM's. I have this code which is working
$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"
}
I have VM with name es-client-node1
, es-client-node2
, es-master-node1
, es-data-node1
& es-data-node1
. I want to get IP address of just client node or VM's name matches with es-client-node*
, similarly for datanode & master node into different variable
any idea how to do this in powershell ?
Upvotes: 0
Views: 10385
Reputation: 2206
For getting private IP using PowerShell you can use this command:
$IP = (Get-AzureRmNetworkInterface -Name $VMName -ResourceGroupName $RGName).IpConfigurations.PrivateIpAddress
Upvotes: 7
Reputation: 7199
az network nic list --query '[*].{Name:name,PrivateIpAddress:ipConfigurations[0].privateIpAddress,ResourceGroup:resourceGroup}'
Upvotes: 0