How to Configure Windows Defender Controlled Folder Access Using PowerShell

Ransomware attacks inflict catastrophic damage by rapidly iterating through personal and corporate directories, encrypting documents, spreadsheets, and databases with uncrackable asymmetric ciphers. Microsoft Defender Controlled Folder Access (CFA) provides active behavioral ransomware defense by locking down designated storage directories. Only verified, cryptographically signed applications can modify files within protected locations, while unknown scripts and unapproved executables are immediately blocked.

How Controlled Folder Access Defends Against Ransomware

Controlled Folder Access operates as an essential component of Microsoft Defender Exploit Guard:

  • Whitelisted Execution: Analyzes executable reputation via Microsoft Defender SmartScreen cloud intelligence before permitting write, delete, or rename operations.
  • Default Protected Paths: Automatically protects standard user libraries including Documents, Pictures, Desktop, Videos, and Music.
  • Operational Modes: Supports Audit Mode (monitors and logs write attempts without blocking) and Block Mode (actively denies file modification).

Auditing Current Controlled Folder Access Status

Launch PowerShell as Administrator and query current CFA settings:

# Check Controlled Folder Access operational state
Get-MpPreference | Select-Object -Property EnableControlledFolderAccess, ControlledFolderAccessProtectedFolders, ControlledFolderAccessAllowedApplications

The integer value returned for EnableControlledFolderAccess represents:

  • 0 = Disabled.
  • 1 = Enabled (Block Mode).
  • 2 = Audit Mode (Logs unapproved access attempts to the Event Log without blocking).

Enabling Controlled Folder Access via PowerShell

To enforce ransomware blocking across the operating system:

# Enable Controlled Folder Access in Block Mode
Set-MpPreference -EnableControlledFolderAccess Enabled

# Verify the setting was applied
(Get-MpPreference).EnableControlledFolderAccess

Adding Custom Protected Directories

In addition to default Windows user folders, add proprietary database directories, source code repositories, or network sync targets:

# Add custom proprietary data directory to protected folders list
Add-MpPreference -ControlledFolderAccessProtectedFolders "D:\CorporateData", "C:\Projects"

# Verify protected directories list
(Get-MpPreference).ControlledFolderAccessProtectedFolders

Whitelisting Legitimate Line-of-Business Applications

If bespoke enterprise software or internal developer utilities are falsely blocked from saving files:

# Add trusted application executable to whitelist
Add-MpPreference -ControlledFolderAccessAllowedApplications "C:\Program Files\InternalTool\backup_worker.exe"

# Confirm allowed applications
(Get-MpPreference).ControlledFolderAccessAllowedApplications

Reviewing Blocked Access Events in Windows Event Viewer

Audit blocked file modification attempts using PowerShell:

# Query Defender log for Controlled Folder Access events (Event ID 1123 / 1124)
Get-WinEvent -FilterHashtable @{
    LogName = "Microsoft-Windows-Windows Defender/Operational"
    Id = 1123, 1124
} -MaxEvents 20 | Format-List TimeCreated, Id, Message

Event ID 1123 records blocked write attempts, providing the exact process path and target document path for rapid security auditing.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.