当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 查找特定 SMTP 地址

作者:精品下载站 日期:2024-12-15 00:40:42 浏览:14 分类:玩电脑

使用 PowerShell 查找特定 SMTP 地址


如何使用 PowerShell 在 Exchange 组织中查找特定的 SMTP 地址?您想知道有多少个邮箱配置了特定的 SMTP 地址。在本文中,您将了解如何在 Exchange Server 中搜索和列出具有特定 SMTP 地址的邮箱。

使用 PowerShell 查找特定 SMTP 地址

您可以登录 Exchange 管理中心 (EAC),一一打开邮箱,然后找到特定的 SMTP 地址。然而,我不建议这样做,除非你有很多时间并且喜欢这样度过。

您想要列出 Exchange 组织中的所有 SMTP 地址吗?了解如何使用 PowerShell 列出所有 SMTP 地址 »

注意:以下命令适用于本地 Exchange Server 和 Exchange Online。

在运行命令之前连接 Exchange 管理工具:

  • 本地 Exchange Server: 以管理员身份运行 Exchange Management Shell。

  • Exchange Online:以管理员身份运行 PowerShell 并连接到 Exchange Online PowerShell。

注意:将命令中的Get-Mailbox更改为Get-Recipient以显示组织中的所有对象。这将获取邮箱、通讯组、安全组和联系人。

按域查找特定 SMTP 地址

我们喜欢在 Exchange Server 中查找具有特定 SMTP 地址的邮箱。它们是主 SMTP 地址和辅助 SMTP 地址(也称为别名地址)。

以管理员身份运行 Exchange 命令行管理程序。运行 cmdlet 以列出具有该特定域的邮箱。

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*@a-d.site"} | Sort-Object Name

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                a-d            ex01-2016        Unlimited
Benetiz Anees             Benetiz.Anees        ex01-2016        Unlimited
Boris Campbell            boris.campbell       ex01-2016        Unlimited
Carl Kelly                carl.kelly           ex01-2016        Unlimited
Christopher Payne         christopher.payne    ex01-2016        Unlimited

按名称查找特定 SMTP 地址

也许您想搜索名称而不是域名。您需要改变什么才能使之成为可能?将域 *@a-d.site 更改为包含 SMTP 地址的名称。例如,*tajran*。这将在所有 SMTP 字段中搜索具有该名称的所有内容。

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*tajran*"} | Sort-Object Name

Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
Administrator             Administrator        ex01-2016        Unlimited
Ali Tajran                a-d            ex01-2016        Unlimited
Benetiz Anees             Benetiz.Anees        ex01-2016        Unlimited
Boris Campbell            boris.campbell       ex01-2016        Unlimited
Carl Kelly                carl.kelly           ex01-2016        Unlimited
Christopher Payne         christopher.payne    ex01-2016        Unlimited

列出信息丰富的结果

调整表视图并将所需的信息添加到 Select-Object cmdlet。例如,DisplayName、PrimarySMTPAddress 和 EmailAddresses。

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*@a-d.site"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses | Where-Object {$_ -clike "smtp*"}}} | Select-Object DisplayName, PrimarySMTPAddress, EmailAddresses | Sort-Object DisplayName

DisplayName       PrimarySmtpAddress          EmailAddresses
-----------       ------------------          --------------
Administrator     [email protected]     {smtp:[email protected], smtp:[email protected]}
Ali Tajran        [email protected]        smtp:[email protected]
Benetiz Anees     [email protected]     smtp:[email protected]
Boris Campbell    [email protected]    {smtp:[email protected], smtp:[email protected]}
Carl Kelly        [email protected]        smtp:[email protected]
Christopher Payne [email protected] smtp:[email protected]

调整输出以获得更清晰的视图

为了使外观更清晰,请从辅助 SMTP 地址中删除 smtp:

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*@a-d.site"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName

DisplayName       PrimarySmtpAddress          EmailAddresses
-----------       ------------------          --------------
Administrator     [email protected]     [email protected], [email protected]
Ali Tajran        [email protected]        [email protected]
Benetiz Anees     [email protected]     [email protected]
Boris Campbell    [email protected]    [email protected], [email protected]
Carl Kelly        [email protected]        [email protected]
Christopher Payne [email protected] [email protected]

导出至 CSV 文件

我们希望将具有特定 SMTP 地址的邮箱导出为 CSV。这会将 CSV 文件导出到 C:\temp\。不要忘记在 C 驱动器上创建临时文件夹或编辑导出路径。

[PS] C:\>Get-Mailbox -ResultSize Unlimited -Filter {EmailAddresses -like "*@a-d.site"} | Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={($_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}) -join ","}} | Sort-Object DisplayName | Export-CSV "C:\temp\Specific_SMTP_Addresses.csv" -NoTypeInformation -Encoding UTF8

使用 Microsoft Excel 或其他 CSV 文件查看器/编辑器打开导出的 CSV 文件。

[玩转系统] 使用 PowerShell 查找特定 SMTP 地址

我希望它能帮助您搜索并列出配置了特定 SMTP 地址的邮箱。

继续阅读:如何使用 PowerShell 批量删除辅助 SMTP 地址 »

结论

您了解了如何使用 PowerShell 在 Exchange Server 中查找特定的 SMTP 地址。在 PowerShell 中运行 cmdlet 以获取具有特定 SMTP 地址的邮箱列表。使用您想要查看的值调整 Select-Object cmdlet。之后,将列表导出到 CSV 文件并使用您喜欢的 CSV 查看器/编辑器打开它。

您喜欢这篇文章吗?您可能还喜欢使用随机密码批量创建 AD 用户。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯