Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Using WMI to return multiple ipv4 addresses

$
0
0

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?


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>