从 Exchange 用户邮箱中搜索和删除邮件
今天的文章将介绍如何从 Exchange 用户邮箱中搜索和删除邮件。某个用户向整个组织发送了一封电子邮件,该组织包含一千多个用户,并且所有用户都有一个邮箱。任务是从组织中的每个邮箱中删除电子邮件。如何从Exchange用户邮箱中搜索和删除邮件?
信息
我们唯一拥有的就是该电子邮件的主题。您想知道如何获取电子邮件的主题并从邮箱中删除该特定电子邮件吗?阅读文章搜索并删除 Exchange 用户邮箱中的电子邮件。
导出所有用户的电子邮件地址
将所有拥有邮箱的用户导出到 CSV 文件。 CSV 文件将包含所有电子邮件地址的列表。首先,在C:驱动器上创建一个文件夹并将其命名为temp。该文件夹将类似于 C:\temp\。
以管理员身份运行 Exchange 命令行管理程序。运行 cmdlet 以获取用户的所有电子邮件地址的列表。
[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress | Sort-Object PrimarySmtpAddress | Export-Csv "c:\temp\user_mailboxes.csv" -NoTypeInformation -Encoding UTF8转到 CSV 文件并确保属性 PrimarySmtpAddress 显示。它将显示在第一行。
您可以使用 Microsoft Excel 编辑 CSV 文件并删除不想搜索的用户。在我们的示例中,我们需要所有用户邮箱并保持原样。
在 PowerShell 中导入 CSV 文件
在下一步中运行 cmdlet 之前,请在 PowerShell 中导入 CSV 文件。这是检查它是否可读以及是否已准备就绪的绝佳方法。
了解更多:导入 CSV 分隔符 PowerShell »
[PS] C:\>Import-Csv "C:\temp\user_mailboxes.csv"
DisplayName SamAccountName PrimarySmtpAddress
----------- -------------- ------------------
Administrator Administrator Administrator@exoip.com
Tajran, Ali Ali.Tajran Ali.Tajran@exoip.com
Amanda Morgan Amanda.Morgan Amanda.Morgan@exoip.com
Nash, Amelia Amelia.Nash Amelia.Nash@exoip.com
Campbell, Boris Boris.Campbell Boris.Campbell@exoip.com
Christopher Payne Christopher.Payne Christopher.Payne@exoip.com
Piper, Dylan Dylan.Piper Dylan.Piper@exoip.com
Rees, Grace Grace.Rees Grace.Rees@exoip.com
Springer, Irene Irene.Springer Irene.Springer@exoip.com
Teneres, Jasmina Jasmina.Teneres Jasmina.Teneres@exoip.com
Fisher, Jonathan Jonathan.Fisher Jonathan.Fisher@exoip.com
Davidson, Kylie Kylie.Davidson Kylie.Davidson@exoip.com
Clark, Leonard Leonard.Clark Leonard.Clark@exoip.com
Fisher, Madeleine Madeleine.Fisher Madeleine.Fisher@exoip.com
Walsh, Mary Mary.Walsch Mary.Walsh@exoip.com
Fraser, Max Max.Fraser Max.Fraser@exoip.com
Scott, Melanie Melanie.Scott Melanie.Scott@exoip.com
Discovery Search Mailbox SM_5aab23c8c7d6435eb MsExchDiscoveryMailboxD919BA05-46A6-415f-80AD-7E09334BB852@exoip.com
Murray, Nicholas Nicholas.Murray Nicholas.Murray@exoip.com
Bower, Piers Piers.Bower Piers.Bower@exoip.com
Grant, Richard Richard.Grant Richard.Grant@exoip.com
Room Tokyo roomtokyo roomtokyo@exoip.com
Dickens, Ruth Ruth.Dickens Ruth.Dickens@exoip.com
Nolan, Sebastian Sebastian.Nolan Sebastian.Nolan@exoip.com
Rees, Zoë Zoe.Rees Zoe.Rees@exoip.com从 Exchange 中搜索和删除邮件
我们要从所有 Exchange 用户邮箱中删除的邮件是由 Boris 发送的。主题是:说再见从来都不容易。
从 CSV 文件中搜索并删除消息
我们想要搜索 CSV 文件中的所有用户并删除具有该特定主题的电子邮件。确保最后添加了-Force开关。否则,你必须不断确认每个邮箱。
[PS] C:\>Import-Csv "C:\temp\user_mailboxes.csv" | ForEach-Object {Search-Mailbox $_.PrimarySmtpAddress -SearchQuery 'Subject:"Saying goodbye is never easy"' -DeleteContent -Force}
WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console
in the Exchange Administration Center.
RunspaceId : 188c72af-79d0-4de8-b2bb-f4f5dda01814
Identity : exoip.local/Users/Administrator
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 1
ResultItemsSize : 9.21 KB (9,431 bytes)
WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console
in the Exchange Administration Center.
RunspaceId : 188c72af-79d0-4de8-b2bb-f4f5dda01814
Identity : exoip.local/Company/Users/IT/Ali Tajran
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 1
ResultItemsSize : 9.184 KB (9,404 bytes)
WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console
in the Exchange Administration Center.
RunspaceId : 188c72af-79d0-4de8-b2bb-f4f5dda01814
Identity : exoip.local/Company/Users/Finance/Amanda Morgan
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 1
ResultItemsSize : 9.2 KB (9,421 bytes)它确实从 CSV 文件中指定的 Exchange 用户邮箱中搜索并删除邮件。
搜索并删除所有邮箱中的邮件
如果您希望在没有 CSV 文件的情况下定位所有用户邮箱,请使用 Get-Mailbox cmdlet。
[PS] C:\>Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery 'Subject:"Saying goodbye is never easy"' -DeleteContent -Force
WARNING: The Search-Mailbox cmdlet returns up to 10000 results per mailbox if a search query is specified. To return more than 10000 results, use the New-MailboxSearch cmdlet or the In-Place eDiscovery & Hold console
in the Exchange Administration Center.
RunspaceId : 188c72af-79d0-4de8-b2bb-f4f5dda01814
Identity : exoip.local/Users/Administrator
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 1
ResultItemsSize : 9.21 KB (9,431 bytes)
RunspaceId : 188c72af-79d0-4de8-b2bb-f4f5dda01814
Identity : exoip.local/Company/Users/IT/Ali Tajran
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 1
ResultItemsSize : 9.184 KB (9,404 bytes)
RunspaceId : 188c72af-79d0-4de8-b2bb-f4f5dda01814
Identity : exoip.local/Company/Users/Finance/Amanda Morgan
TargetMailbox :
Success : True
TargetFolder :
ResultItemsCount : 1
ResultItemsSize : 9.2 KB (9,421 bytes)它确实从所有 Exchange 用户邮箱中搜索并删除邮件。
验证结果
我们来看看克里斯托弗的邮箱。我们可以确认该消息已被删除。
该邮件将不会发送到已删除邮件文件夹。恢复消息的唯一方法是通过备份软件。
该邮件将从所有 Exchange 用户邮箱中删除。它能为您提供帮助吗?
继续阅读:删除 Exchange Server 中的邮箱数据库 »
结论
您了解了如何从 Exchange 用户邮箱中搜索和删除邮件。获取您要删除的邮件主题。之后,运行本文中显示的 cmdlet 之一以删除该消息。
您喜欢这篇文章吗?您可能还喜欢在 Outlook 中将所有邮件标记为已读。不要忘记关注我们并分享这篇文章。



