PowerShell: Finding IP Address

There are various ways to determine the IP address that is assigned to your machine. Here is a rather unusual approach that uses text operators to filter the information out of the results provided by ipconfig.exe.

This is not the most solid way of getting to an IP address. It is, however, an interesting brain teaser illustrating the power of PowerShell:

PS> foreach($ip in (ipconfig) -like '*IPv4*') { ($ip -split ' : ')[-1]}

One thought on “PowerShell: Finding IP Address

  1. Here’s a better option showing which NIC the IP is assigned to:
    Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName .

Leave a Reply

Your email address will not be published.