array IndexOf IPv4 subnets


I have an array of subnets like

PS C:\> $Subnet2update


I like to find the index of a subnet in the array

[array]::IndexOf($Subnet2update, but it give me always a False

What do I wrong? (PS version is 5.1 on Win10)

Is it because I'm working with IPv4 addresses?

  • How are you generating and passing in this array.
    If you are getting false, that means this is not an array but a string.

    You also need to quote that CIDR to be syntactically correct. Special characters have meaning in PowerShell, unless that are coerced as a string. Hence the need for the quotes.

        ($ips = 1..254 | % {"10.10.10.$_/24"})

        # Results

        [array]::IndexOf($ips, '')


Reply Children
No Data