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]}
192.168.2.105
192.168.56.1

One Response to “PowerShell: Finding IP Address”

  1. Mike April 21, 2014 at 9:00 am #

    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

revia in alcoholism