Turn On Defender Ransomware Protection (Controlled Folder Access) via PowerShell
Use Set-MpPreference to enable controlled folder access so only trusted apps can modify your documents.
01Command
$ Set-MpPreference -EnableControlledFolderAccess Enabled02What it does
Microsoft Defender includes a ransomware shield called Controlled Folder Access: once enabled, untrusted apps are blocked from writing to your Documents, Pictures, Videos, and Music folders, so ransomware can't encrypt them silently. The Settings app hides this switch behind menus and some editions hide it entirely, but one PowerShell command turns it on. Adding specific folders or allowed apps is done with -AddProtectedFolder and -AddControlledFolderAccessAllowedApplication.
03Risk
04Undo
$ Set-MpPreference -EnableControlledFolderAccess Disabled05Sources
- Protect important folders with controlled folder access | Microsoft LearnEvidence: Controlled folder access lets only trusted apps make changes to protected folders; it can be enabled via Set-MpPreference -EnableControlledFolderAccess.
Last verified: 2026-09-18 · Category: Security & Privacy
06Related solutions
Read the Authenticode signature status and signer of any executable or script in PowerShell.
Understand PowerShell's execution policy scopes and set the one that lets you run your own local scripts without gutting the security model.
Search inside text files and logs with regex, returning file, line number and match.