guide · static export
Security · defender

Add a Defender Exclusion and Prove It Applies

Exclusions are the difference between a build that takes two minutes and one that takes twenty. They are also the setting most often configured on the wrong path — and quietly ignored.

by@guidox updated:10/31/26 time:20 min level:Intermediate tested on:Windows 11 24H2 works on:Windows 10, Windows 11 tools:PowerShell as administrator
TL;DR

Add the folder with **Add-MpPreference -ExclusionPath**, read it back with **Get-MpPreference** and confirm the effective policy. Managed machines override local exclusions silently.

Before you start

Requirements

  • Admin rights
  • The exact folder that causes the slowdown
  • 20 minutes
Step by step

Instructions

01

Read the exclusions that already exist

**Get-MpPreference** lists paths, processes and extensions. Starting from the current list prevents duplicates and shows whether a previous admin already covered the folder.

Get-MpPreference | Select-Object -ExpandProperty ExclusionPath
Get-MpPreference | Select-Object -ExpandProperty ExclusionProcess
Get-MpPreference | Select-Object -ExpandProperty ExclusionExtension
02

Choose the narrowest form that works

A folder is broader than a process and a process is broader than a file extension. Exclude the build output folder first, and add a process only when the folder is not enough.

Add-MpPreference -ExclusionPath 'D:\Build\obj','D:\Build\bin'
Add-MpPreference -ExclusionProcess 'msbuild.exe','cl.exe'
Get-MpPreference | Select-Object -ExpandProperty ExclusionPath
⚠ warningAn excluded folder is not scanned at all. Never exclude a download directory, a user profile or anything that receives files from the internet.
03

Check whether a policy owns the setting

On a managed machine the values from Group Policy or Intune win over local ones. **Get-MpPreference** then shows your addition while the engine ignores it, which is the confusing case.

Get-MpPreference | Select-Object DisableAutoExclusions,ExclusionPath
reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Exclusions\Paths" /s
Get-MpComputerStatus | Select-Object AntivirusEnabled,RealTimeProtectionEnabled,AMServiceEnabled
04

Prove the exclusion by behaviour

The list is only a claim. Run a scan on that exact folder: without the exclusion the files are read and counted, with it they are skipped, which is visible in the scan duration and the file count.

$f = 'D:\Build\obj'
Start-MpScan -ScanType CustomScan -ScanPath $f
Get-MpComputerStatus | Select-Object QuickScanStartTime,FullScanStartTime
Get-WinEvent -LogName 'Microsoft-Windows-Windows Defender/Operational' -MaxEvents 10 | Select-Object TimeCreated,Id,Message
05

Confirm the engine sees the path correctly

Trailing backslashes, mapped drives and environment variables are the three usual reasons an exclusion does nothing. Defender matches literal paths, so use the drive letter form.

Test-Path 'D:\Build\obj'
(Get-Item 'D:\Build\obj').FullName
Get-MpPreference | Select-Object -ExpandProperty ExclusionPath | ForEach-Object { [pscustomobject]@{ Path = $_; Exists = (Test-Path $_) } }
06

Keep the list small over time

Every exclusion is a gap. Review the list quarterly, remove what a project no longer needs, and record why each entry exists.

Remove-MpPreference -ExclusionPath 'D:\Build\bin'
Get-MpPreference | Select-Object -ExpandProperty ExclusionPath
Get-Content C:\Build\exclusions.txt -ErrorAction SilentlyContinue
Troubleshooting

Common issues

The exclusion is listed but the scan still reads the files

A policy exclusion list is in force and takes over the whole set. Check the registry path under Policies and the Intune configuration.

Add-MpPreference fails with access denied

The cmdlet needs an elevated session, and Tamper Protection blocks changes on some builds. Check Get-MpComputerStatus for IsTamperProtected.

A third-party antivirus is installed

Defender runs in passive mode and its exclusions do nothing. Configure the equivalent rule in the product that actually scans.

Exclusions disappear after a reboot

A management tool rewrites them. Add the exclusion at the source instead of fighting it locally.

FAQ

Frequently asked

Does an exclusion disable real-time protection?

No. It only removes those files, folders or processes from scanning; everything else stays protected.

Can a normal user add exclusions?

No. The change requires elevation and is usually restricted by policy on business machines.

How to undo this

Remove each entry with Remove-MpPreference -ExclusionPath, -ExclusionProcess or -ExclusionExtension, then confirm with Get-MpPreference. Policy-managed exclusions must be removed where they are defined.

Changelog · 1 entry
  1. 2026-10-31
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress