通过PowerShell查询并排除Exchange相关进程
# 以管理员身份运行以下脚本
# 查询所有含"exchange"的进程
$exchProcesses = Get-Process | Where-Object { $_.Path -match "exchange" } | Select-Object -ExpandProperty Path -Unique
# 添加到Defender排除列表
foreach ($process in $exchProcesses) {
Add-MpPreference -ExclusionProcess $process
Write-Host "已排除进程: $process"
}
# 显示排除结果
Get-MpPreference | Select-Object -ExpandProperty ExclusionProcess
#配置防火墙排除规则
$exchProcesses = Get-Process | Where-Object { $_.Path -match "exchange" } | select-Object -Unique Path
foreach ($proc in $exchProcesses) {
$path = $proc.Path
if (-not [string]::IsNullOrEmpty($path)) {
# 添加入站规则
New-NetFirewallRule -DisplayName "Allow Exchange Inbound - $($path.Split('\')[-1])" `
-Direction Inbound -Program $path -Action Allow
# 添加出站规则
New-NetFirewallRule -DisplayName "Allow Exchange Outbound - $($path.Split('\')[-1])" `
-Direction Outbound -Program $path -Action Allow
}
}