I have the following code snippet and I cannot figure out why the
$query_means = read-host 'Enter one of psinfo, powershell or wmic'
if ($query_means -ne "wmic" -OR $query_means -ne "psinfo" -OR $query_means -ne "powershell")
$query_means = read-host 'Invalid entry. Enter one of psinfo, powershell or wmic'
}Until ($query_means -eq "wmic" -OR $query_means -eq "psinfo" -OR $query_means -eq "powershell")
You are using the wrong operator. Let's say that
wmic. Then your first condition of
if statement is
false, however other two conditions are
true. Since you are using
OR operator, the result is
OR operator you will always have at least 2 conditions that evaluate to
true, so the overall result will always be
Instead you should be using
AND operator, because you want condition to be valid when neither of the strings are in the list you provided.
-AND and your code should be fine:
if ($query_means -ne "wmic" -AND $query_means -ne "psinfo" -AND $query_means -ne "powershell")