Add Defender Exclusions with PowerShell (Add-MpPreference)

Skip antivirus scanning for a build folder or a trusted process using the Defender module's Add-MpPreference.

WindowsdefenderadminpowershellMedium risk
Run Add-MpPreference -ExclusionPath <folder> or -ExclusionProcess <name> in an elevated PowerShell.

01Command

Command
$ Add-MpPreference -ExclusionPath 'D:\dev\build' ; Add-MpPreference -ExclusionProcess 'node.exe'

02What it does

Real-time scanning of huge build outputs (node_modules, obj/bin, Docker layers) is a classic cause of slow development machines, and exclusions are the documented remedy. Exclusions can be scoped by path, extension, or process name, and Get-MpPreference shows what is currently set. Each exclusion weakens protection — Microsoft recommends narrow, specific paths rather than whole drives, since malware in an excluded folder is invisible to Defender.

03Risk

RiskMedium risk
RequirementsRequires an elevated PowerShell session; Defender must be the active antivirus
!Warning: Every exclusion weakens your antivirus protection; exclude only specific trusted folders, never whole drives.

04Undo

Undo
$ Remove-MpPreference -ExclusionPath 'D:\dev\build' ; Remove-MpPreference -ExclusionProcess 'node.exe'

05Sources

Last verified: 2026-09-17 · Category: Security & Privacy

06Related solutions