A PowerShell script that migrates OneDrive-redirected folders back to their local counterparts and completely removes OneDrive from Windows.
- Detects the OneDrive root folder (
$env:OneDriveor%USERPROFILE%\OneDrive). - Moves all files and sub-folders from each OneDrive-hosted known folder to its local equivalent:
OneDrive path Local path …\OneDrive\Desktop~\Desktop…\OneDrive\Documents~\Documents…\OneDrive\Downloads~\Downloads…\OneDrive\Pictures~\Pictures…\OneDrive\Music~\Music…\OneDrive\Videos~\Videos - Resets Windows Shell Folder registry keys so that all apps point to the local paths again (uses both registry values and
SHSetKnownFolderPath). - Stops all OneDrive processes (
OneDrive.exe,OneDriveStandaloneUpdater.exe). - Uninstalls OneDrive via its own setup executable (
/uninstall). - Deletes leftover OneDrive program files and the (now-empty) OneDrive data folder.
- Cleans up OneDrive registry entries and startup entries.
- Removes OneDrive from the Windows Explorer navigation pane.
- Windows 10 or Windows 11
- PowerShell 5.1 or later
- Administrator privileges (the script will refuse to run without them)
Open an elevated PowerShell prompt (Run as Administrator) and run:
# Run the full migration and removal
.\Remove-OneDrive.ps1
# Preview all actions without making any changes (dry-run)
.\Remove-OneDrive.ps1 -WhatIf
# Override the OneDrive path if it is in a non-standard location
.\Remove-OneDrive.ps1 -OneDrivePath "D:\OneDrive"Tip: A reboot (or at minimum a restart of Windows Explorer) is recommended after running the script so that all shell folder changes take full effect.
- Files that already exist in the destination folder are skipped (not overwritten) to avoid accidental data loss.
- The script uses PowerShell's built-in
-WhatIfsupport, so every destructive operation respects the-WhatIfflag. - If OneDrive is already uninstalled, the script gracefully skips the uninstallation step.