【发布时间】:2017-06-18 13:14:21
【问题描述】:
我正在尝试在 powershell 中创建邮箱权限审核,并希望从 powershell 脚本中的输出中删除特定帐户,而不是之后手动删除。
为了做到这一点,我正在寻找一种方法来将数组的内容与 powershell 中的单个字符串进行比较。
例如,如果我要声明一个数组:
$array = "1", "2", "3", "4"
然后我想找到一种方法来执行以下操作:
$a = "1"
$b = "5"
if ($a -ne *any string in $array*) {do something} #This should return false and take no action
if ($b -ne *any string in $array*) {do something} #This should return true and take action
我不知道如何实现这一点,感谢任何帮助
【问题讨论】:
-
-in或 -contains? msdn.microsoft.com/powershell/reference/5.1/…$a = 'g'; $b = @('g','t'); $a -in $b -
if($array -notcontains $a){...}
标签: arrays powershell if-statement for-loop compare