Pause Syncing with PowerShell
I would like a way to pause and unpause OneDrive syncing in PowerShell. This would be handy in PowerShell scripts that manipulate files. Sometimes the files get locked if OneDrive is currently syncing them. I would like to be able to script the pause, make my file changes, then unpause when my script is finished.
My scripts run throughout the night and in the morning, every morning, my one drive is stuck pending syncing. I'm seeking a scheduled task to pause and resume every few hours to kick off the syncing process
Peter L commented
I run SAS, which produces output as HTML, one file per page and graphic., which can be a lot of files. I then post-process these files. OneDrive slows both parts of this dramatically.
I would like a programmatic way to pause OneDrive as SAS starts and resume when it finishes.
This need is so much greater now we are all working from home on slow links, where OneDrive can have a big effect on performance.
Many resort to pausing OneDrive for the whole day. If Microsoft wants us to work more collaboratively, they should provide a better solution to this, which would make it possible to leave OneDrive on for most of the time.
Diarmuid Deans commented
I am not a Powershell expert, but working on the information at this link:
I worked out how to stop and start Onedrive with a simple command in Powershell. I have a couple of comments to add.
1. In Windows 8.1 the executable file is not groove.exe, I found it at C:\Users\MyUserName\AppData\Local\Microsoft\OneDrive\onedrive.exe
2. You do not open Powershell with elevated rights for this operation.
My plan is to create two one-line powershell scripts and run them on a schedule using task manager on a Windows SBS 2011 machine, using the information at this link:
My experience is that OneDrive hogs bandwidth (even when you limit it in settings) and I don't want it to synchronise during business hours. I will start OneDrive in the evening and stop it in the early morning. I haven't set it up yet, so I can't say if it works, but all the signs look promising.
Powershell and OneDrive do not get along well. In one script I open an Excel file, which is set to auto refresh some SQL data, then save the Excel file, close the workbook and quit the application with these last 3 lines:
Works fine until the last line, which causes a sync failure in OneDrive, perhaps because it executes too quickly. If I leave the last line out, the file syncs fine.
This would also help with scheduled backups using the Windows 7 Backup tool, which Files on Demand and OneDrive syncing have caused to fail in Windows 10 1803 and 1809. While I do not back up the OneDrive folders, the system image attempts to do so and fails.
James redmore commented
Or any powershell endpoints for that matter. No good way to proactively monitor user workstations to ensure sync is running and healthy.