SharePoint synced library removed from OneDrive sync but local folder won’t delete (160GB, access denied)
Posted by javina34@reddit | sysadmin | View on Reddit | 21 comments
I’m troubleshooting a SharePoint library that was synced to File Explorer using the SharePoint Sync button (OneDrive sync client).
We removed the sync successfully and verified the library is no longer listed under OneDrive synced locations.
However, the local folder still exists at:
C:\Users\User\companyname.com\folder
The folder is no longer syncing, but it remains on disk.
I attempted:
- Deleting through File Explorer (progress reached 100% but folder remained)
- rmdir /s /q (access denied)
- Taking ownership via NinjaOne command line, but ownership became SYSTEM instead of admin
- Confirmed OneDrive sync relationship is removed
Library size is around 160GB.
Has anyone dealt with an orphaned SharePoint/OneDrive synced folder that won’t delete after unsyncing? Looking for the cleanest way to remove the local cache without affecting SharePoint online data.
bluecollarbiker@reddit
NinjaOne service runs as local system, so takeown via ninjaone is going to change the owner to local system…
You can change the owner to the local administrators group and grant that group full access. You may have to stop the OneDrive process as it may be protecting that folder. Worst case delete and rebuild the users profile.
Apachez@reddit
Wouldnt it work if you just boot on Hiren Boot CD from a USB instead?
bluecollarbiker@reddit
Possibly. Present day you’d likely have to deal with disk encryption. So you’d need to be able to unlock the drive or otherwise you have to decrypt the drive, do the needful, re-encrypt the drive.
Creative-Type9411@reddit
what about UnlockIt?
gitblametherapy04@reddit
UnlockIt is solid for that, it bypasses the Windows file locking that usually causes these access denied errors, especially when the OneDrive client holds a handle even after sync is removed
Creative-Type9411@reddit
whenever I post tech advice, I get downvoted for working solutions 🤣
frosty3140@reddit
if Owner = SYSTEM now, then using PSEXEC from Sysinternals would let you run a CMD line or Powershell or even Explorer as SYSTEM.
bluecollarbiker@reddit
Why bother with psexec? Op already has an interactive system shell via NinjaOne.
gitblametherapy04@reddit
Fair point, adding psexec when you've already got interactive access is just extra steps and potential headaches with service dependencies and session isolation.
Josh_Fabsoft@reddit
This is a classic OneDrive sync client issue. The folder gets "orphaned" when the sync relationship is broken but Windows still thinks some process has a lock on it.
A few things to try in order:
Process cleanup first: Open Task Manager and end any OneDrive.exe processes, then try deleting again.
Safe mode approach: As davidokongo mentioned, boot to safe mode and delete from command prompt. This bypasses most file locks.
PowerShell with force: Try
Remove-Item "C:\Users\User\companyname.com\folder" -Recurse -Forcefrom an elevated PowerShell window.Handle.exe from Sysinternals: Download Handle.exe and run
handle.exe "folder"to see what process is locking it, then kill that specific process.Reboot and immediate delete: Sometimes a fresh boot gives you a window before OneDrive services start up where you can delete it.
The UnlockIt suggestion is solid too if the above doesn't work.
For future reference, before removing SharePoint sync, it's often cleaner to move any important files elsewhere first, then remove the sync relationship. The OneDrive client sometimes doesn't handle the cleanup gracefully, especially with large libraries.
If this keeps happening across multiple users, you might want to script the cleanup process or consider group policy settings that better control OneDrive sync behavior.
Mdi1981@reddit
If system is the owner you can try psexec -s cmd. This should open a cmdbox as system.
ExceptionEX@reddit
I've had this issue before, it was an issue with the onedrive client, we removed the onedrive client, then removed it, reinstalled onedrive, and reset the user up.
Any-Personality-8517@reddit
Had det same issue with mulitple devices. This was the only thing that fixed it.
ThrowAwayTheTeaBag@reddit
Very this. My org changed names early days and suddenly I had this issue. Orphaned one drive folders, can't delete. It's just easier to remove one drive, clear all folders, and reinstall and let it sync. Mine admittedly was a pain because I had over 20gb and our office internet isn't as steller as it could be, but the actual process to clear the orphaned folders was easy.
cyberman0@reddit
If you haven't tried yet, login to the machine in safe mode to stop anything in the background starting. Try deleting it and see if it takes and stays gone after a restart in normal. The client could be running in the background locking the folder up.
Master-IT-All@reddit
You'll want to reset OneDrive, /reset from the command line. That should fix this issue if I recall correctly from a similar issue I assisted on late last year.
Bodycount9@reddit
If it is no longer syncing then whatever happens you cant affect sharepoint data.
Syncing in sharepoint is hit or miss. I've seen it work great and I've seen it stop syncing for no reason and I have to reinstall onedrive to get it to sync again.
Also seen it where multiple people sync the same sharepoint. Someone goes in and makes massive changes on sharepoint and then someone's sync client reverts all those changes to what it was before.
I always tell people to not use sync unless you absolutely have to. And never sync the entire documents folder. Only sync single folders inside documents.
SubstantialAsk4123@reddit
I used a command to take ownership of the files as admin recursively, then delete.
Creative-Type9411@reddit
Try this, its free - UnlockIt
https://emcosoftware.com/unlock-it
Bodycount9@reddit
Im guessing this doesn't work for a network lock like onedrive or sharepoint would be? Just local files that are locked by your computer resources?
davidokongo@reddit
Restart in safe mode CMD and nuke it from there.
That worked for me a few years back. Give it a try!