powershellpowershell-v6.0

Find all IP addresses from array


I have a lot of arrays which looks like

$a = 'Handshake', 'Success', 'Status', 200, '192.30.253.113', 'OK', 0xF

Information contained in this array may be different but there are IP addresses always in it (one or more, maximum three). I looking for a way for extract these addresses from array(s). What is the simplest way to do it? I ask your attention that position of IP addresses in arrays is various.


Solution

  • $a.Where{!($_ -as [Double]) -and $_ -as [IPAddress]}
    

    Or if you wanna be sure that IP addresses are valid use regular expression shown by @JulienNury