guide · static export
Security · security

Encrypt a Folder with EFS and Back Up the Key

Encrypting File System protects a folder against another account on the same PC and against someone who pulls the drive. Without the certificate export, a reinstall makes the data unreadable forever.

by@guidox updated:10/31/26 time:25 min level:Advanced tested on:Windows 11 24H2 Pro works on:Windows 10 Pro, Windows 11 Pro, Windows Server 2019 tools:PowerShell as administrator, Certificate Manager
TL;DR

Encrypt with **cipher /e /s:D:\vault**, then export the certificate with **Export-PfxCertificate** before you store anything important. The key, not the password, is what decrypts the files.

Before you start

Requirements

  • Windows Pro, Enterprise or Education
  • An NTFS volume
  • Admin rights for the certificate export
  • 25 minutes
Step by step

Instructions

01

Check the edition and the file system

EFS is not available on Home editions, and it needs NTFS. **Get-Volume** shows the file system, and the edition string decides whether the cipher commands will do anything.

Get-Volume -DriveLetter D | Select-Object DriveLetter,FileSystem,FileSystemType
(Get-ComputerInfo).WindowsProductName
Get-WindowsEdition -Online | Select-Object Edition
02

Encrypt the folder and everything inside it

**cipher /e** sets the encrypted attribute, and **/s** applies it to the directory tree. New files created inside an encrypted folder inherit the attribute automatically.

New-Item -ItemType Directory D:\vault -Force | Out-Null
cipher /e /s:D:\vault
Get-ChildItem D:\vault | Select-Object Name,Attributes
(cipher /s:D:\vault) | Select-Object -First 5
03

Confirm that a second account is locked out

The protection is per user certificate, not per machine. A second local account that is not a recovery agent sees access denied, which is the actual test of the setup.

cipher /c D:\vault\secret.txt
Get-ChildItem D:\vault | Select-Object Name,Length,LastWriteTime
whoami /user
04

Export the certificate and the private key

**Export-PfxCertificate** writes both parts into one protected file. Store it off the machine: a key on the encrypted volume is worth nothing when the volume is gone.

$c = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.EnhancedKeyUsageList.ObjectId -contains '1.3.6.1.4.1.311.10.3.4' } | Select-Object -First 1
$c | Select-Object Subject,Thumbprint,NotAfter
$pw = Read-Host -AsSecureString 'PFX password'
Export-PfxCertificate -Cert $c -FilePath E:\backup\efs-$env:COMPUTERNAME.pfx -Password $pw
05

Restore the key on a fresh install

**Import-PfxCertificate** puts the key back into the personal store, and the files open again after a sign-in. The same password you set at export is required.

$pw = Read-Host -AsSecureString 'PFX password'
Import-PfxCertificate -FilePath E:\backup\efs-PC01.pfx -CertStoreLocation Cert:\CurrentUser\My -Password $pw
Get-ChildItem Cert:\CurrentUser\My | Select-Object Subject,Thumbprint,HasPrivateKey
cipher /c D:\vault\secret.txt
06

Decrypt again and retire the old key

**cipher /d** removes the attribute from the tree. Files stay readable by any account with NTFS permissions afterwards, which is exactly why the export belongs in a safe place until the data is gone.

cipher /d /s:D:\vault
Get-ChildItem D:\vault | Select-Object Name,Attributes
Remove-Item Cert:\CurrentUser\My\<thumbprint> -Force
⚠ warningDeleting the certificate before the data is decrypted locks you out permanently. Remove it last, and only after the backup copy is verified.
Troubleshooting

Common issues

cipher says the file system does not support encryption

The volume is exFAT, FAT32 or a network share. EFS needs a local NTFS volume; move the folder or reformat, and keep a backup first.

The files are not green after encrypting

The folder only shows the attribute for new files. Encrypt the existing tree with cipher /e /s, and check the attribute column instead of the colour.

A different account can still open the files

That account is an EFS recovery agent or an administrator with the key. Check cipher /c for the listed users and remove the recovery agent in a local policy.

Export-PfxCertificate fails with access denied

The private key is marked as non-exportable. Try certmgr.msc with the Export wizard; if the key was created as non-exportable, it cannot be backed up.

FAQ

Frequently asked

Is EFS the same as folder compression?

No. Compression shrinks the data and saves space; EFS protects the content with a key. Both set an attribute on the folder, and both can be on at the same time.

Does EFS protect files on a USB stick?

Only if the stick is formatted NTFS. On exFAT the command fails, so use a container file on an NTFS volume instead.

What happens if I forget the password but keep the PFX?

The PFX password is what you set, not your Windows password. Keep it with the file, or the export cannot be imported.

How to undo this

Run cipher /d /s:D:\vault to decrypt the tree, then delete the exported PFX and the certificate from Cert:\CurrentUser\My once the data is confirmed readable.

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

Free · no account needed · tracks your progress