Get-ChildItem -Path C:\inetpub\mailroot\Badmail -Include *.bad -Recurse | Select-String -Pattern "To: *@*.com"
我的查询输出我只想要电子邮件地址本身。目前,我的输出看起来像这样
C:\inetpub\mailroot\Badmail\003b91651170707201800000012.BAD:2:To: user@domain.com
C:\inetpub\mailroot\Badmail\003b91651170707201800000012.BAD:46:To: user@domain.com
C:\inetpub\mailroot\Badmail\003c11119100507201800000007.BAD:2:To: user@domain.com
C:\inetpub\mailroot\Badmail\003c11119100507201800000007.BAD:47:To: user@domain.com
C:\inetpub\mailroot\Badmail\003c11119100507201800000007.BAD:48:Reply-To: user@domain.com
C:\inetpub\mailroot\Badmail\003c60245022007201800000009.BAD:2:To: user@domain.com
C:\inetpub\mailroot\Badmail\003c60245022007201800000009.BAD:47:To: user@domain.com
C:\inetpub\mailroot\Badmail\003c60245022007201800000009.BAD:48:Reply-To: user@domain.com
C:\inetpub\mailroot\Badmail\003e61810232107201800000010.BAD:2:To: user@domain.com
C:\inetpub\mailroot\Badmail\003e61810232107201800000010.BAD:46:To: user@domain.com
答案 0 :(得分:3)
您已经很近了,但是您同时也在捕获Reply-To
(如果打算这样做,则不知道)。您可以使用捕获组来仅确定电子邮件地址:
Get-ChildItem -Path C:\inetpub\mailroot\Badmail -Filter *.bad -Recurse |
Select-String -Pattern 'To:\s(.+@.+\.com)' |
ForEach-Object { $PSItem.Matches.Groups[1].Value }