Sorting an array of IP addresses is one of those things that’s not quite as clean and simple as would be nice.
Fortunately, the process can be simplified greatly by converting an IP address to decimal for the sort operation. To do this, I like to use ConvertTo-DecimalIP from my NetShell module (or my collection of subnet maths functions).
"10.1.10.10", "192.168.1.42", "172.16.1.1", "127.0.0.1" | Sort-Object { ConvertTo-DecimalIP $_ }
Short and simple.
Related posts:
- More IPv4 subnet maths with PowerShell I’ve been extended and upgrading my library of network functions...
Related posts brought to you by Yet Another Related Posts Plugin.
Post a Comment