理解 PowerShell 比较运算符

huangapple go评论64阅读模式
英文:

Understanding PowerShell Comparators

问题

我有一个包含许多列的CSV文件,其中之一是电子邮件。
当我尝试搜索CSV文件以查看是否包含指定的电子邮件地址时,只有"-like"运算符返回true。

帮助我理解为什么"-in"和"-contains"在这种情况下不起作用?

```plaintext
英文:

I have a csv that contains a lot of columns, one of which is email.
When I try to search the CSV to see if it contains the specified email address, only the -like operator returns true.

Help me understand why "-in" and "-contains" won't work in this scenario?

$path = import-csv -path "C:\temp\file.csv"
$email = "*John.Doe@company.com*"

if ($path -like $email){
    write-host "LIKE"
}
if ($email -in $path){
    write-host "IN"
}
if ($path -contains $email){
    write-host "CONTAINS"
}

答案1

得分: 1

如果您要导入具有多个列的CSV,例如名称和电子邮件,您首先需要告诉PowerShell您要查找的是哪一列:

$path.Email -contains $email
英文:

If you are importing a CSV with multiple columns, like for example Name, and Email, you need to tell powershell first which column it is your looking for:

$path.Email -contains $email

huangapple
  • 本文由 发表于 2023年8月4日 01:15:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76830290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定