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.
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.