I have to check if the variables $var1, $var2, $var3 contain "172.20.110." or "172.20.111.". Is there a way to this with an IF statement (not a beautiful solution) or is there a better way to that. For Example: Can I create a "network object" with 172.20.110.0/23 (255.255.254) and check the variables against it?
1 Answer
The simplest solution is probably to use -match to find "172.20.110" in $var1. The -match operator returns a bool that you can check. You can figure out the if statements to compare them how you need. Check out this link for more on comparison operators that you might rather use.
$var1 = "somestuff172.20.110morestuff"
if($var1 -match "172.20.110"){"was true"}
else{"was false"}
$var1looks like; what you wan't to compare with what.