Azure Powershell - find the NIC based on the private IP

I am very new to Azure and Powershell. I need to find my Network Interface based on the private IP address. I found "Get-AzNetworkInterface" cmdlet and I want it to return only the entry that contains the IP. I noticed that the IP only exists in "IpConfigurationsText" but not in the "IpConfigurations" which only contains an object name. I don't know if this is normal. The returned "IpConfigurationText" is a list (based on my limited python experience) with dictionary key-value pairs like this

[
 {
   "Name": "xxxx",
   "Id": "xxxx",
   "PrivateIpAddress": "10.1.2.3",
   ...
 }
]

I guess I want to filter based on its content. I have tried the following but none succeeded...

Get-AzNetworkInterface | Where-Object { $_.IpConfigurationsText["PrivateIpAddress"] -contains "10.1.2.3" }
Get-AzNetworkInterface | Where-Object { $_.IpConfigurationsText[0]["PrivateIpAddress"] -eq "10.1.2.3" }

I also tried to display only the IP in the output instead of the dictionary key-value pair without success too

Get-AzNetworkInterface | select Name,IpConfigurationsText["PrivateIpAddress"]

Let me know what I missed.

By the way, I also found out I can use the "Out-GridView" to see and filter the result but it doesn't show me the entire output when it is big. It got truncated. I also can't seem to do copy/paste on it... Any advice on that too?

Thanks! Difan


Solution 1:

try this:

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

if you don`t have the module you need to install i:

Login-AzureRmAccount
Install-Module AzureRm

more info