powershell - 如何在powershell中使用多个值进行比较

标签 powershell

简单来说,我正在尝试 -

$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/

相关文章:

powershell - 使用当前日期时间将日期时间添加到数据表中?

powershell - 如何加快PowerShell foreach循环

powershell - 串联Powershell命令

powershell - 使用 Powershell 获取 Azure AD token (jwt)

python - Awk 比较 3 个值,第一个文件值之间的第二个文件值,两个文件之间的多列打印输出到第三个

regex - 是否可以使用 `switch -regex` 获取匹配位置

shell - 在执行路径中使用变量

powershell - Win32Shutdown 一般故障

powershell - 使用 powershell AzureVM 将列添加到 CSV 文件

powershell - TFS Powershell cmdlet 在 ISE 中不起作用