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

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

作者:精品下载站 日期:2024-12-14 06:46:29 浏览:16 分类:玩电脑

如何确定哪些活动规则影响电子邮件附件


MS-220 Exchange Online 故障排除考试的要求之一是您应该能够确定哪些活动邮件流规则会影响电子邮件附件。如果您是 Exchange 管理员并且有用户向您报告他们没有收到来自发件人的预期邮件附件,则此功能非常有用。

在本教程中,我将向您展示如何使用 Exchange 管理中心和 PowerShell 来查找影响附件的活动邮件流规则。

先决条件

要完成此任务,您必须是 Microsoft 365 中 Exchange 管理员组或全局管理员组的成员。

此外,为了运行本教程中必要的脚本,您还应该安装 Exchange Online PowerShell 模块。请参阅我的有关如何安装 Exchange Online PowerShell 模块的教程。

使用 Exchange 管理中心确定哪些活动规则会影响电子邮件附件

要使用 Exchange 管理中心 Web UI 查找哪些活动规则影响邮件附件,请按照以下步骤操作。

1. 首先登录 Exchange 管理中心:https://admin.exchange.microsoft.com/

2. 从左侧菜单中,展开邮件流并选择规则

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

3. 使用左上角的搜索框并搜索单词“附件”。这还将搜索包括规则条件的规则描述。

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

4. 您现在只会看到名称或描述中包含“附件”一词的搜索结果。然后,您可以手动单击每个规则来确定条件和操作。

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

确定哪些活动规则影响电子邮件附件 使用 PowerShell

要使用 PowerShell 生成影响电子邮件附件的规则条件的报告,您可以使用以下脚本。该脚本可能有点过度设计,但它会将“数组列表”类型条件转换为字符串,然后将整个变量转换为字符串,然后将数据提取到可以搜索或导出的标题列中。

您需要手动定义的唯一参数是 $rulename 变量,我在其中使用下面的示例作为“阻止某些消息”。

#Connect to Exchange Online
Connect-ExchangeOnline

#Store exact rule name
$rulename = "Block certain messages"

#Store rule parameters which affect attachments
$attachmentrules = get-transportrule "$rulename" | Select *attachment*

#Convert array objects to string
$string1 = $attachmentrules.AttachmentExtensionMatchesWords | out-string
$attachmentrules.AttachmentExtensionMatchesWords = $string1
$string2 = $attachmentrules.AttachmentNameMatchesPatterns | out-string
$attachmentrules.AttachmentNameMatchesPatterns = $string2
$string3 = $attachmentrules.AttachmentPropertyContainsWords | out-string
$attachmentrules.AttachmentPropertyContainsWords = $string3
$string4 = $attachmentrules.AttachmentContainsWords | out-string
$attachmentrules.AttachmentContainsWords = $string4
$string5 = $attachmentrules.AttachmentMatchesPatterns | out-string
$attachmentrules.AttachmentMatchesPatterns = $string5
$string6 = $attachmentrules.ExceptIfAttachmentNameMatchesPatterns | out-string
$attachmentrules.ExceptIfAttachmentNameMatchesPatterns = $string6
$string7 = $attachmentrules.ExceptIfAttachmentExtensionMatchesWords | out-string
$attachmentrules.ExceptIfAttachmentExtensionMatchesWords = $string7
$string8 = $attachmentrules.ExceptIfAttachmentPropertyContainsWords | out-string
$attachmentrules.ExceptIfAttachmentPropertyContainsWords = $string8
$string9 = $attachmentrules.ExceptIfAttachmentSizeOver | out-string
$attachmentrules.ExceptIfAttachmentSizeOver = $string9
$string10 = $attachmentrules.ExceptIfAttachmentContainsWords | out-string
$attachmentrules.ExceptIfAttachmentContainsWords = $string10
$string11 = $attachmentrules.ExceptIfAttachmentMatchesPatterns | out-string
$attachmentrules.ExceptIfAttachmentMatchesPatterns = $string11
$string = "$attachmentrules"

#Create Report object
$Report = [System.Collections.Generic.List[Object]]::new()

#Define regex parameters
$reg = [RegEx]"(\w+)=(\w*)"

#Create report to review
$table=@()
$table = $reg.Matches($string) | ForEach-Object {
    $rhs = if($_.Groups[2].Value){
        $_.Groups[2].Value
    }else{
        "N/A"
    }
    $obj = [PSCustomObject][ordered]@{
        "TYPE" = $_.Groups[1].Value
        "VALUE" = $rhs
    }
    $Report.Add($obj)
} | Format-Table

#Display report in session
$report

#Export report to CSV
$report | export-csv C:\temp\MailRuleAttachmentInfo.csv -NoTypeInformation

我还对上述内容进行了扩展,下面的脚本将使用 PowerShell 生成有关 Exchange Online 中所有传输规则的报告。在这种情况下,您不需要指定任何变量,因为它将循环遍历每个规则并生成输出。

#Connect to Exchange Online
Connect-ExchangeOnline

#Create Report object
$Report = [System.Collections.Generic.List[Object]]::new()

#Store all transport rules
$alltransportrules = get-transportrule

#Loop through all transport rules
ForEach ($Rule in $alltransportrules){

#Store rule parameters which affect attachments
$attachmentrules = get-transportrule $rule.name | Select *attachment*

#Convert array objects to string
$string1 = $attachmentrules.AttachmentExtensionMatchesWords | out-string
$attachmentrules.AttachmentExtensionMatchesWords = $string1
$string2 = $attachmentrules.AttachmentNameMatchesPatterns | out-string
$attachmentrules.AttachmentNameMatchesPatterns = $string2
$string3 = $attachmentrules.AttachmentPropertyContainsWords | out-string
$attachmentrules.AttachmentPropertyContainsWords = $string3
$string4 = $attachmentrules.AttachmentContainsWords | out-string
$attachmentrules.AttachmentContainsWords = $string4
$string5 = $attachmentrules.AttachmentMatchesPatterns | out-string
$attachmentrules.AttachmentMatchesPatterns = $string5
$string6 = $attachmentrules.ExceptIfAttachmentNameMatchesPatterns | out-string
$attachmentrules.ExceptIfAttachmentNameMatchesPatterns = $string6
$string7 = $attachmentrules.ExceptIfAttachmentExtensionMatchesWords | out-string
$attachmentrules.ExceptIfAttachmentExtensionMatchesWords = $string7
$string8 = $attachmentrules.ExceptIfAttachmentPropertyContainsWords | out-string
$attachmentrules.ExceptIfAttachmentPropertyContainsWords = $string8
$string9 = $attachmentrules.ExceptIfAttachmentSizeOver | out-string
$attachmentrules.ExceptIfAttachmentSizeOver = $string9
$string10 = $attachmentrules.ExceptIfAttachmentContainsWords | out-string
$attachmentrules.ExceptIfAttachmentContainsWords = $string10
$string11 = $attachmentrules.ExceptIfAttachmentMatchesPatterns | out-string
$attachmentrules.ExceptIfAttachmentMatchesPatterns = $string11
$string = "$attachmentrules"

#Define regex parameters
$reg = [RegEx]"(\w+)=(\w*)"

#Create report to review
$table=@()
$table = $reg.Matches($string) | ForEach-Object {
    $rhs = if($_.Groups[2].Value){
        $_.Groups[2].Value
    }else{
        "N/A"
    }
    $obj = [PSCustomObject][ordered]@{
        "RULE NAME" = $Rule.name
        "TYPE" = $_.Groups[1].Value
        "VALUE" = $rhs
    }
    $Report.Add($obj)
} | Format-Table
}

#Display report in session
$report

#Export report to csv 
$report | export-csv C:\temp\AllMailRuleAttachmentInfo.csv -NoTypeInformation

如果你有很多规则,输出将会相当大。您应该使用 Excel 中的“筛选”功能来适当减少结果。

  1. 导航到 C:\temp 并打开 CSV 文件。

2. 调整列的宽度,然后选择值列,单击顶部的数据选项卡,然后单击过滤器

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

3. 单击旁边的下拉箭头并取消选中“N/A”和“False”

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

4. 现在您只剩下有意义的信息。

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

禁用影响规则

确定哪些规则影响电子邮件附件后,您可以禁用该规则,同时进一步解决问题的根本原因。

通过 Exchange 管理中心禁用规则

1. 登录 Exchange 管理中心后,展开邮件流并选择规则

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

2. 在列表中找到您想要禁用的规则,然后单击规则名称。

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

3. 单击启用或禁用规则滑块以禁用规则。

[玩转系统] 如何确定哪些活动规则影响电子邮件附件

使用 PowerShell 禁用规则

首先,要查看所有启用的规则,您可以运行以下命令:

Get-TransportRule | Where-Object {$_.State -eq "Enabled"}

然后,您可以使用以下脚本来定位特定规则,确保将规则标识更改为与目标规则匹配的规则名称。

$Rule = Get-TransportRule -Identity "Block .exe attachments"

If ($rule.state -eq "Enabled") {
   Disable-TransportRule -Identity $Rule.Name -confirm:$false
    Write-host $rule.name ": has been disabled" -ForegroundColor black -BackgroundColor green
} Else {
    Write-host $rule.name ": is already disabled" -ForegroundColor black -BackgroundColor yellow
}

您还可以在我的 GitHub 上查看上述所有脚本。

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

取消回复欢迎 发表评论:

关灯