Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 680 Bytes

sort-ipv4-address-as-version.md

File metadata and controls

24 lines (17 loc) · 680 Bytes

Sort IPv4 Addresses as Version

Use the Scriptblock `{$_ -as [version]} to sort an array of IPv4 addresses.

Running these commands should result in a sorted list.

$ips = @("192.168.5.25","192.168.5.1","192.168.6.18","192.168.5.10")
$ips | Sort-Object {$_ -as [version]}     

Results:

192.168.5.1
192.168.5.10
192.168.5.25
192.168.6.18

References

  • This method and many others are summarized in this ISC Diary by Rob VandenBrink.
  • Rob's write-up was in inspired by this thread on Twitter.