r/PowerShell • u/rexm3 • Jan 12 '26
Script Sharing PowerShell un-sync script
I'm looking for a customizable script to stop OneDrive from syncing specific SharePoint sites/libraries. Then after the sync has completely stopped, removing the local files remaining of that specific site. Does anybody have a script for this already or any tips on this?
I would like the option to hard code the specific libraries to un-sync as I might need to execute it using RMM software.
8
Upvotes
1
u/Dragennd1 Jan 12 '26
The only thing I can think of would be to try and locate the related registry keys for the sync'd libraries in question and remove the keys for those libraries. Unsure if this would break the sync or not though.
1
u/Rivereye Jan 12 '26
You can set a SharePoint library up so that SYNC is unavailable. If someone is already syncing it, I do believe that changing the library like this removes it from PCs
1
u/purplemonkeymad Jan 12 '26
I don't believe there are any automation interfaces on the od desktop app. (aside from the odopen links to add syncs.) You might be able to open the databases in local appdata and see if any store the sync status of the libraries. But hitting internal structures of programs can lead to instability or sudden changes on the app side.
1
u/tlourey Jan 12 '26
I remember the command line options used to be documented on Ms learn but I can't find them now.
Here is an old PowerShell module someone wrote but it hasn't been updated in some time. It may give you some ideas.
https://www.powershellgallery.com/packages/Onedrive-client/0.2.2/Content/Onedrive-client.psm1
1
u/BlackV Jan 12 '26 edited Jan 12 '26
There was a post regarding this a few days ago, but I have not seen it again was /r/sysadmin or /r/intune
EDIT: Ah boo sorry, the powershell was not for removing the sync
https://www.reddit.com/r/Intune/comments/1q9apu6/new_blog_post_where_i_dive_deep_in_sharepoint_vs/
https://tob-it.se/the-complete-lifecycle-of-sharepoint-sync-in-intune-add-it-accelerate-the-sync-from-intune-remove-it-and-how-it-compares-to-add-shortcut-to-onedrive/