Find NIC by IP address

2k views Asked by At

I need to be able to find a NIC by IP address, whether full or partial. So writing something like:

Get-NIC-By-IP 10.10.*

Could return:

Ethernet

I know how to do this in Bash but haven't been able to find a PowerShell solution to this.

2

There are 2 answers

4
Jan_V On BEST ANSWER

By using the following command you will receive every interface which matches the IP-addres which you mention in the match clause.

Get-NetIPAddress | ?{ $_.AddressFamily -eq "IPv4" -and ($_.IPAddress -match "192.")} | Select-Object InterfaceAlias

In my case this is:

InterfaceAlias
--------------
Ethernet 2
Ethernet

Of course, you can modify the output if necessary.

Supplement for old OS'es

You can't run this script on old Windows browsers as the cmdlet isn't included according to this thread on TechNet: https://social.technet.microsoft.com/Forums/office/en-US/dcc966a1-24c2-4ae4-b39d-b78df52b6aef/install-of-powershell-3-on-windows-7-seems-to-be-missing-modules?forum=winserverpowershell

There are many cmdlets in Powershell for Windows 8 and Server 2012 (PS V3) that are not included in the V3 release for Windows 7.  An example would be Get-NetIPAddress, and many other network-related cmdlets.

Then again, it might be a good idea to upgrade the OS to a supported version (if possible of course).

0
Jeff Zeitlin On

For versions of Windows and/or PowerShell that do not support Get-NetIPAddress, you can get the requisite information with a combination of the WMI queries for the classes Win32_NetworkAdapterConfiguration and Win32_NetworkAdapter:

$Configs = Get-WMIObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled='TRUE'" | Where-Object {$_.IPAddress -like "192.168.*"}
ForEach ($Config in $Configs) {
    Get-WMIObject -Class Win32_NetworkAdapter -Filter "Index=$($Config.Index)" | Select-Object NetConnectionID,Description
}