OneDrive Sync/Stop Sync - delete local files

%3CLINGO-SUB%20id%3D%22lingo-sub-2087898%22%20slang%3D%22en-US%22%3EOneDrive%20Sync%2FStop%20Sync%20-%20delete%20local%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2087898%22%20slang%3D%22en-US%22%3E%3CP%3ELooking%20for%20a%20solution%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUser%20syncs%20SPOL%20library%3C%2FP%3E%3CP%3EUser%20stops%20Sync%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELocal%20file%2Ffolder%20structure%20remains%20-%20Looking%20for%20ideas%20on%20script%20that%20can%20run%20and%20delete%20those%20local%20files%2Ffolder%20once%20status%20goes%20from%20Sync%20to%20Stop%20Sync%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20endpoints%20are%20intune%20Azure%20Joined%20-%20so%20we%20can%20push%20out%20a%20script%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20first%20need%20to%20understand%20how%20OneDrive%20StopSync%20command%20communicates%20with%20the%20OS%20so%20I%20can%20use%20that%20as%20a%20trigger.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3C%2FP%3E%3CP%3ESJ%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2087898%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ewindows%2010%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2310720%22%20slang%3D%22en-US%22%3ERe%3A%20OneDrive%20Sync%2FStop%20Sync%20-%20delete%20local%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2310720%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20the%20same%20question%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F643732%22%20target%3D%22_blank%22%3E%40ScottonTap%3C%2FA%3E%26nbsp%3Bdoes%20-%20how%20can%20we%20tell%20clients%20that%20our%20staff%20no%20longer%20have%20access%20to%20files%20if%20we%20cannot%20delete%20them%20from%20their%20machines%20after%20removing%20Sharepoint%20access%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20'Sync'%20option%20should%20automatically%20be%20turned%20off%20after%20access%20is%20withdrawn%2C%20meaning%20we%20should%20then%20be%20able%20to%20run%20a%20powershell%20script%20to%20delete%20the%20local%20copy%20of%20the%20folder.%20Currently%20even%20if%20I%20click%20'stop%20sync'%20on%20the%20folder%20I'm%20still%20met%20with%20Powershell%20telling%20me%20I%20can't%20delete%20the%20folder%20because%20'Access%20to%20the%20cloud%20file%20is%20denied'%20if%20I%20run%20the%20below%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERemove-Item%20-Recurse%20-Force%20%22local%20path%20name%22%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Looking for a solution

 

User syncs SPOL library

User stops Sync

 

Local file/folder structure remains - Looking for ideas on script that can run and delete those local files/folder once status goes from Sync to Stop Sync - 

 

The endpoints are intune Azure Joined - so we can push out a script - 

 

But first need to understand how OneDrive StopSync command communicates with the OS so I can use that as a trigger. 

 

Thanks,

SJ

1 Reply

I have the same question @ScottonTap does - how can we tell clients that our staff no longer have access to files if we cannot delete them from their machines after removing Sharepoint access?

 

The 'Sync' option should automatically be turned off after access is withdrawn, meaning we should then be able to run a powershell script to delete the local copy of the folder. Currently even if I click 'stop sync' on the folder I'm still met with Powershell telling me I can't delete the folder because 'Access to the cloud file is denied' if I run the below:

 

Remove-Item -Recurse -Force "local path name"