Using WMI to return multiple ipv4 addresses

The following block of code works great for returning multiple active IP addresses on a machine:

gwmi Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Select-Object -ExpandProperty IPAddress

However, I noticed that for some reason the values that are returned by default are always sorted largest to smallest and I am looking for a way to have them sorted by primary/secondary values instead. For example, I have a machine with 2 static ipv4 addresses assigned and 1 dhcp ipv6 address:

ipv4 primary: 192.168.1.105

ipv4 secondary: 192.168.1.106

ipv6: fe80::79e6:ef0b:b963:79a9

The results returned show up like this:

192.168.1.106

192.168.1.105

fe80::79e6:ef0b:b963:79a9

Is there a way to have this sorted so that the first value returned ($_.IPAddress[0]) will always be the primary IP address of the machine and not just the largest numbered value?

July 8th, 2013 3:32pm

Hi,

If you know your adapter that the primary IP address used, then we could query only that adapter.

The below blog should be helpful:

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/24/use-powershell-to-change-ip-behavior-with-skipassource.aspx

In addition, please also refer to the below thread:

http://social.technet.microsoft.com/Forums/windowsserver/en-US/9eb57eed-ad57-49e7-8b96-b4d4bcbaff0e/detect-the-primary-ip-address-mac-ect

Regards,

Yan Li

If you have any feedback on our support, please click here .

Free Windows Admin Tool Kit Click here and download it now
July 10th, 2013 2:59am

Hi,

Just checking in to see if the suggestions were helpful. Please let us know if you would like further assistance.

If you have any feedback on our support, please click here .

July 14th, 2013 10:55pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics