简单来说,我正在尝试 -
$animal = "cat", "dog", "rabbit"
$animal -contains "dog" # -----> Getting true, which is working!
但是,当我尝试检查多个值时,例如 -
$animal -contains "dog" -and "bat" # --> still getting a "True" response.
如何使用 contains 运算符检查多个值?
最佳答案
bool 表达式的工作方式略有不同。你需要这个:
$animal -contains "dog" -and $animal -contains "bat"
您还可以将“dog”和“bat”放入它们自己的数组中,然后循环遍历该数组。
关于powershell - 如何在powershell中使用多个值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74210811/