A PowerShell script to fully uninstall Microsoft OneDrive from Windows, including a scheduled post-reboot cleanup task to remove leftover folders and files.
- Windows 10 or 11
- PowerShell 5.1+
- Must be run as Administrator
Save the script as Remove-OneDrive.ps1 and run it from an elevated PowerShell session.
.\Remove-OneDrive.ps1.\Remove-OneDrive.ps1 -Reboot.\Remove-OneDrive.ps1 -BlockReinstall.\Remove-OneDrive.ps1 -BlockReinstall -Reboot| Parameter | Type | Description |
|---|---|---|
-Reboot |
Switch | Automatically reboots after scheduling the cleanup task |
-BlockReinstall |
Switch | Sets a Group Policy registry key (DisableFileSyncNGSC) to prevent OneDrive from being reinstalled |
-PostReboot |
Switch | Internal use. Run by the scheduled task after reboot to complete folder cleanup |
-UserProfilePath |
String | Override the user profile path used for cleanup (defaults to $env:USERPROFILE) |
- Stops the running OneDrive process
- Runs
OneDriveSetup.exe /uninstallfromSystem32and/orSysWOW64 - (Optional) Blocks reinstall via a registry policy key
- Schedules a post-reboot task (runs as SYSTEM at startup) to remove leftover folders:
%USERPROFILE%\OneDrive%USERPROFILE%\AppData\Local\Microsoft\OneDrive%ProgramData%\Microsoft OneDrive
- After reboot, the scheduled task runs automatically and deletes itself when done
- The script must be saved and run from a
.ps1file — it will not work when pasted directly into a PowerShell session, because it schedules itself as a post-reboot task using$MyInvocation.MyCommand.Path. - The
-BlockReinstallflag writes toHKLM:\SOFTWARE\Policies\Microsoft\Windows\OneDrive. This can be reversed by deleting that registry key. - If you prefer not to reboot immediately, the cleanup task will run automatically on the next system startup.
MIT