用 PowerShell 添加 Defender 排除项(Add-MpPreference)
使用 Defender 模块的 Add-MpPreference 让杀毒扫描跳过指定的构建目录或可信进程。
在管理员 PowerShell 中运行 Add-MpPreference -ExclusionPath <目录> 或 -ExclusionProcess <进程名>。
01命令
命令
$ Add-MpPreference -ExclusionPath 'D:\dev\build' ; Add-MpPreference -ExclusionProcess 'node.exe'02作用说明
实时扫描庞大的构建产物(node_modules、obj/bin、Docker 层)是开发机变慢的常见原因,排除项就是官方给出的解决方法。排除可以按路径、扩展名或进程名设置,用 Get-MpPreference 可查看当前配置。每条排除都会削弱防护——微软建议只排除精确的可信目录而不是整个盘,因为排除文件夹中的恶意软件对 Defender 完全不可见。
03风险
!注意: 每条排除项都会削弱杀毒防护;只排除明确的可信目录,切勿排除整个磁盘。
04撤销
撤销
$ Remove-MpPreference -ExclusionPath 'D:\dev\build' ; Remove-MpPreference -ExclusionProcess 'node.exe'05来源
- Add-MpPreference (Defender module)依据: Documents the Add-MpPreference cmdlet and its -ExclusionPath / -ExclusionProcess parameters.
- Configure and validate exclusions for Microsoft Defender Antivirus scans依据: Documents path, extension and process exclusions, and warns that exclusions create a gap in protection and should be as specific as possible.
最后验证: 2026-09-17 · 分类: 安全与隐私