[玩转系统] 使用 PowerShell 批量删除辅助 SMTP 地址
作者:精品下载站 日期:2024-12-15 00:40:28 浏览:15 分类:玩电脑
使用 PowerShell 批量删除辅助 SMTP 地址
在上一篇文章中,您学习了如何使用 PowerShell 列出所有 SMTP 地址。我们可以看到邮箱配置了多个 SMTP 地址。这些辅助 SMTP 地址也称为别名地址。在本文中,您将了解如何使用 PowerShell 批量删除辅助 SMTP 地址。
介绍
Remove-SMTP.ps1 PowerShell 脚本适用于:
本地交换
交换混合
在线交流
准备删除 SMTP 地址 PowerShell 脚本
下载Remove-SMTP.ps1 脚本或将以下代码复制并粘贴到记事本中。将其命名为 Remove-SMTP.ps1 并将其放置在 C:\scripts 文件夹中。如果没有脚本文件夹,请创建一个。
# Output will be added to C:\temp folder. Open the Remove-SMTP-Address.log with a text editor. For example, Notepad.
Start-Transcript -Path C:\temp\Remove-SMTP-Address.log -Append
# Get all mailboxes
$Mailboxes = Get-Mailbox -ResultSize Unlimited
# Loop through each mailbox
foreach ($Mailbox in $Mailboxes) {
# Change @contoso.com to the domain that you want to remove
$Mailbox.EmailAddresses | Where-Object { ($_ -clike "smtp*") -and ($_ -like "*@contoso.com") } |
# Perform operation on each item
ForEach-Object {
# Remove the -WhatIf parameter after you tested and are sure to remove the secondary email addresses
Set-Mailbox $Mailbox.DistinguishedName -EmailAddresses @{remove = $_ } -WhatIf
# Write output
Write-Host "Removing $_ from $Mailbox Mailbox" -ForegroundColor Green
}
}
Stop-Transcript
第 11 行:将 *@contoso.com 值更改为要从邮箱中删除的域。
举几个例子:
示例 1:仅删除域为 www.a-d.site 的 SMTP 地址。添加“*@a-d.site”。
示例 2:删除所有名为 tajran 的 SMTP 地址。添加“*tajran*”。
在我的例子中,它看起来是这样的。
# Output will be added to C:\temp folder. Open the Remove-SMTP-Address.log with a text editor. For example, Notepad.
Start-Transcript -Path C:\temp\Remove-SMTP-Address.log -Append
# Get all mailboxes
$Mailboxes = Get-Mailbox -ResultSize Unlimited
# Loop through each mailbox
foreach ($Mailbox in $Mailboxes) {
# Change @contoso.com to the domain that you want to remove
$Mailbox.EmailAddresses | Where-Object { ($_ -clike "smtp*") -and ($_ -like "*tajran*") } |
# Perform operation on each item
ForEach-Object {
# Remove the -WhatIf parameter after you tested and are sure to remove the secondary email addresses
Set-Mailbox $Mailbox.DistinguishedName -EmailAddresses @{remove = $_ } -WhatIf
# Write output
Write-Host "Removing $_ from $Mailbox Mailbox" -ForegroundColor Green
}
}
Stop-Transcript
在下一步中,您将运行该脚本并查看其实际效果。
批量删除辅助 SMTP 地址 PowerShell 脚本
该脚本适用于 Exchange 本地、Exchange 混合和 Exchange Online。在运行脚本之前,您必须连接正确的工具:
本地 Exchange/Exchange 混合:以管理员身份运行 Exchange 命令行管理程序。
Exchange Online (Microsoft 365/Office 365):以管理员身份运行 PowerShell 并连接到 Exchange Online PowerShell。
转到脚本路径并运行Remove-SMTP.ps1 脚本。该脚本将遍历 Exchange 组织中的所有邮箱。值得高兴的是,脚本中添加了 -WhatIf 参数。如果运行该脚本,环境中不会发生任何事情。您将得到一个输出,显示将会发生什么。
在我的示例中,所有包含 tajran 的 SMTP 地址都将被批量删除。运行脚本后,确认这些是需要删除的 SMTP 地址。
[PS] C:\>cd \scripts
[PS] C:\scripts>.\Remove-SMTP.ps1
Transcript started, output file is C:\temp\Remove-SMTP-Address.log
What if: Setting mailbox "Kyle Peake".
Removing smtp:[email protected] from Kyle Peake Mailbox
What if: Setting mailbox "Kylie Davidson".
Removing smtp:[email protected] from Kylie Davidson Mailbox
What if: Setting mailbox "Larson Tevin".
Removing smtp:[email protected] from Larson Tevin Mailbox
What if: Setting mailbox "Madeleine Ross".
Removing smtp:[email protected] from Madeleine Ross Mailbox
What if: Setting mailbox "Mary Walsh".
Removing smtp:[email protected] from Mary Walsh Mailbox
What if: Setting mailbox "Max Fraser".
Removing smtp:[email protected] from Max Fraser Mailbox
Transcript stopped, output file is C:\temp\Remove-SMTP-Address.log
从 PowerShell 脚本中删除 -WhatIf 参数并重新运行该脚本。 SMTP 地址被批量删除。
[PS] C:\scripts>.\Remove-SMTP.ps1
Transcript started, output file is C:\temp\Remove-SMTP-Address.log
Removing smtp:[email protected] from Kyle Peake Mailbox
Removing smtp:[email protected] from Kylie Davidson Mailbox
Removing smtp:[email protected] from Larson Tevin Mailbox
Removing smtp:[email protected] from Madeleine Ross Mailbox
Removing smtp:[email protected] from Mary Walsh Mailbox
Removing smtp:[email protected] from Max Fraser Mailbox
Transcript stopped, output file is C:\temp\Remove-SMTP-Address.log
我希望这可以帮助您从 Exchange 组织的邮箱中删除不需要的 SMTP 地址。
继续阅读:使用 PowerShell 查找电子邮件地址 »
结论
在本文中,您了解了如何使用 PowerShell 批量删除辅助 SMTP 地址。下载删除 SMTP PowerShell 脚本。添加您要删除的域并运行脚本。脚本输出将显示哪些代理地址被删除。不要忘记首先使用 -WhatIf 参数进行测试,如文章中所示。
您喜欢这篇文章吗?您可能还喜欢使用 PowerShell 获取 Exchange 中所有用户的邮箱大小。不要忘记关注我们并分享这篇文章。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[短剧合集] 2025年06月2日 精选+付费短剧推荐39部
[软件合集] 25年6月2日 精选软件18个
[软件合集] 25年6月1日 精选软件15个
[短剧合集] 2025年06月1日 精选+付费短剧推荐59部
[短剧] 2025年05月31日 精选+付费短剧推荐58部
[软件合集] 25年5月31日 精选软件66个
[电影] 黄沙漫天(2025) 4K.EDRMAX.杜比全景声 / 4K杜比视界/杜比全景声
[风口福利] 短视频红利新风口!炬焰创作者平台重磅激励来袭
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[美图] 2W美女个美女小姐姐,饱眼福
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag