PowerShell - 搜索电子邮件地址并排除某些地址

时间:2016-06-30 06:06:29

标签: regex powershell

Get-ChildItem 'D:\failed log' -Recurse |
  Select-String -AllMatches '\w+@\w+\.\w+' |
  Select-String -NotMatch '\w+@repoinfotec.\w+'| 
  Select-Object FileName

Explanantion
以上管道查找除@ repoinfotec.com

之外的所有电子邮件ID

问题
它应该找到除@ repoinfotec.com和@ bnymellon.com之外的所有电子邮件地址,那么如何排除2? 我应该将它们放入for循环或类似的东西吗?

1 个答案:

答案 0 :(得分:1)

您不需要Get-ChildItem cmdlet,只需将-Path传递给Select-String cmdlet即可。要排除两个域名,请使用正则表达式或|

select-string -Path 'your_file' -Pattern '\w+@\w+\.\w+' | 
    where Line -NotMatch '\w+@(repoinfotec|bnymellon).\w+'
相关问题