攻击者可以访问邮箱帐户的第一件事是设置邮箱转发规则,该规则使他们可以将敏感的数据驱逐到外部电子邮件地址并将其用于恶意目的。因此,必须扫描您的环境并查看是否有任何规则并且没有设置此类意图是必不可少的。在本文中,您将学习如何在Microsoft 365中获得邮箱转发规则 - 与PowerShell在线交换。
外部转发是默认情况下禁用在Microsoft 365中,您应该保持这种方式。但是,如果需要启用外部转发的原因,则应创建出站策略,然后选择授予用于转发外部邮件的用户和组。
重要的:创建一个外出策略,只有选定的用户和组才能转发外部邮件。
Microsoft 365中提供以下类型的自动转发类型:
- 用户可以配置收件箱规则以自动将消息转发给外部发件人
- 管理员可以配置邮箱转发(也称为SMTP转发),以将消息自动转发给外部收件人。管理员可以选择是简单地转发消息,还是在邮箱中保留转发消息的副本。
连接到在线powershell
在开始之前,您必须连接以交换在线PowerShell。否则,命令将不起作用。
获取单个用户的邮箱转发规则
为了获得单个用户的邮箱转发规则。
Get-Mailbox "" | Where-Object { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingsmtpAddress -ne $null) } | ft DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward
输出将显示为这样。
DisplayName UserPrincipalName ForwardingAddress ForwardingSmtpAddress DeliverToMailboxAndForward
----------- ----------------- ----------------- --------------------- --------------------------
Amanda Morgan smtp: True
获取所有用户的邮箱转发规则
为了获得所有用户的邮箱转发规则
Get-Mailbox -ResultSize Unlimited | Where-Object { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingsmtpAddress -ne $null) } | ft DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward
输出将显示这样。
建议阅读:
DisplayName UserPrincipalName ForwardingAddress ForwardingSmtpAddress DeliverToMailboxAndForward
----------- ----------------- ----------------- --------------------- --------------------------
Amanda Morgan smtp: True
Phil Peters smtp: True
SharedMailbox1 smtp: True
SharedMailbox2 smtp: False
邮箱转发PowerShell报告脚本
最好导出邮箱转发规则报告以完成所有内容。
要在单独窗口中的交互式表中获取报告,让我们使用离格视图cmdlet。另外,让我们将其导出到文件夹路径中的CSV文件C:温度。
# Connect Exchange Online PowerShell
Connect-ExchangeOnline
# Change the export path to your desired location
$exportPath = "C:tempForwardingAddress.csv"
# Retrieve mailboxes with forwarding addresses
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ForwardingAddress -ne $null -or $_.ForwardingSmtpAddress -ne $null }
# Select the desired properties for display
$mailboxProperties = $mailboxes | select DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward
# Show the results in an Out-GridView
$mailboxProperties | Out-GridView -Title "Mailboxes with Forwarding Addresses"
# Export all the data to a CSV file
$mailboxProperties | Export-Csv -Path $exportPath -NoTypeInformation -Encoding UTF8
Write-Host "Mailbox data has been exported to $exportPath" -ForegroundColor Green
这就是它在单独的窗口中的外观。

让我们打开CSV文件。


就是这样!
结论
您学会了如何使用Microsoft 365中的PowerShell获得邮箱转发规则。请务必检查组织中是否有外部转发设置的邮箱,并在您看到任何可疑活动时阻止帐户。
您喜欢这篇文章吗?您可能还喜欢在Microsoft 365中的外部电子邮件中添加标签,以获得额外的安全性。不要忘记关注我们并分享这篇文章。