I wonder if someone could help, I am trying to create an array containing multiple sites and if the computer IP matches IP, I want it to list the site but I’m missing something. Code below.
$ip_array is technically a hash table and not an array. GetEnumerator will allow you to loop through the key/value pairs in the hash table. Then, since the values may be an array (Site1 has an array of IP addresses for the value), use -contains to see if the value contains the address you are searching for.
Thanks @darwin-reiswig that worked like a treat. It also started listing all the sites where the IP address did not match so I added a bit more code so It could only match the first 3 octets
Result:
Site3
Site1
Site2
Site: Site1 (< highlighted in green)
I tried adding the below after -match but can’t figure out what I am missing.
'(\d{1,3}).(\d{1,3}).(\d{1,3})
“\d{1,3}.\d{1,3}.\d{1,3}”
(\d{1,3}.\d{1,3}.\d{1,3}.)
If your goal is to match the first 3 octets of the IP address, rather than the entire IP address, that does change the requirements.
Here’s how I would approach it. I would manipulate the value of $myIP to replace the .20 with .1, and then the rest of the code would work as written. Something like this should work: