Reputation: 819
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?
Upvotes: 0
Views: 1691
Reputation: 962
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"}
Upvotes: 1