Secure every file on your own disk first — then remove OneDrive for good.
One ~330-line script · stock PowerShell 5.1 · no installer, no dependencies · safe to re-run
Uninstalling OneDrive the normal way does it in the wrong order: cloud-only files are left behind as unopenable stubs, and Desktop / Documents / Pictures keep pointing into a dead OneDrive folder. UnDrive flips the order:
- Secure — downloads every cloud-only placeholder (needs internet), then
moves everything to
C:\Users\<you>\LocalFiles, preserving folder structure, and points Desktop / Documents / Pictures back at your local profile. - Remove — only after step 1 succeeds and you type YES: uninstalls OneDrive, deletes its leftover data folders, removes the Explorer sidebar entry and autostart, and sets the Windows policy that keeps it from coming back.
- Report — how many files moved and where, what was removed, and anything skipped so you can follow up.
Your cloud copies stay untouched in your Microsoft account, and the script is safe to re-run — every step checks state first and skips what's already done.
Grab undrive.ps1 (or git clone https://github.com/alonbaron/UnDrive), then from an elevated PowerShell
(right-click → Run as administrator):
powershell -ExecutionPolicy Bypass -File .\undrive.ps1To preview every action without changing anything:
powershell -ExecutionPolicy Bypass -File .\undrive.ps1 -DryRunWhat exactly gets removed
- The OneDrive app —
OneDriveSetup.exe /uninstall(System32 / SysWOW64), or the per-user uninstaller registered in HKCU if there's no system copy. %LOCALAPPDATA%\Microsoft\OneDriveand%ProgramData%\Microsoft OneDrive— settings, logs, caches. Never user files.- Your old OneDrive folder — but only once it is verifiably empty.
- The Explorer sidebar entry and the autostart (Run key) entry.
- Sets policy
DisableFileSyncNGSC = 1, so Windows never relaunches it.
Warning
Before any manual cleanup, open C:\Users\<you>\LocalFiles and verify
your files are all there. UnDrive never deletes user files — don't be the
one who does.
- Mid-sync detection is a heuristic (Windows exposes no public sync-status API): the script refuses to run if OneDrive is active and files changed in the last two minutes.
- Verified with
-DryRunon Windows 11. The uninstall step uses Microsoft's documentedOneDriveSetup.exe /uninstall, but has not been exercised end-to-end on the author's machine — read the final report after a real run. - Sign out and back in afterwards so Explorer picks up the folder changes.
Verify C:\Users\<you>\LocalFiles before any manual cleanup.
Secure first. Remove second. Verify always.