英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论