【发布时间】:2021-05-02 18:26:31
【问题描述】:
我有两个包含电子邮件地址的数组:
$from$newuser
我想将$from 的值输出给用户,但我想为变量$newuser 中也存在的值着色。
因此输出将以白色显示$from 中的所有电子邮件地址,但以绿色显示$newuser 中存在的电子邮件地址。
我不想附加两个变量的值,而是比较两个数组并以绿色显示两个数组中都存在的值。
我正在尝试在 Foreach 中使用 IF,但输出始终为白色。
foreach ($element in $from) {
if($element -contains $newuser) {
write-host $element `n -ForegroundColor Green
} else {
write-host $element `n -ForegroundColor White
}
}
需要一些帮助来找出原因。
谢谢!
【问题讨论】:
-
您的 if 子句中有 $elements 拼写错误。不应该只是 $element 吗?
标签: arrays powershell variables colors output