I am aware that variations of this question have been asked and answered on Super User (see list below). I will explain why I'm asking this question below.
I have a nightly process that runs on a VM and makes changes to a handful of Microsoft Excel spreadsheets. In the morning, several external processes need to read these files (Azure, Zapier, etc.). We rely on OneDrive to synchronize the files between manual changes during the day and automated changes at night.
Sometimes, the automated changes get "trapped" on the VM. This means that external processes and users in the browsers cannot see them until someone logs into the VM and forces OneDrive to resync (often by opening the file and resaving or doing a pause-restart in the OneDrive UI). In the worst cases, there are merge conflicts that have to be unwound and fixed by hand.
I would like to prevent these sorts of errors, and I believe this can be done by forcing OneDrive to upload the VM's changes at the end of the nightly process.
Several solutions for have been proposed in the past:
onedrive.exe /reset(executes, but is slow and makes me nervous)onedrive.exe /shutdown+start onedrive.exe /background(while this looks like what I want, the/backgroundargument no longer works, and starting OneDrive without it doesn't seem to sync anything)Telling OneDrive to "Free Up Space" and then "Always Keep on Device" the file in question (this is done via the UI)
Additionally, via the UI, I have found the following works to resync in my case: Pause Syncing (2 Hours) -> Resume Syncing
However, to my knowledge, only one of these is viable in the command line as of the current date (onedrive.exe /reset), and it forces the reloading of all files, which takes quite a while. Additionally, I have been burned by OneDrive in the past, and reloading every file that the VM's account has access to every night feels like asking for trouble.
Is there a better way to do this on the command line?
Now, this question has been asked in various ways:
- How to force OneDrive to synchronize?
- Can you force a single folder/file to sync with OneDrive?
- Start onedrive.exe in silent mode?
- Pause OneDrive sync using cmd (the powershell script provided there relies on /background)
Being the main ones that I have used as resources while trying to fix this issue. Some of the solutions do not work for the command line (to my knowledge), may have worked in the past but are now out of date, and none of them are ideal.
I have tried searching for information on the Microsoft Forums and Microsoft Learn, but as one question puts it, "documentation is really lacking on this one" (there is documentation for the OneDrive API for other services, but nothing as far as the executable that I could find). Therefore, I have elected to ask this question, per the advice in: https://meta.stackoverflow.com/questions/400380/what-should-i-do-if-a-question-has-been-asked-and-answered-but-software-and-an
I recognize that there may not be a better answer than /reset. If that is the only way to get what I want and it won't cause me other issues, I'll use it. If you believe that this problem is caused further up the chain and is not a OneDrive issue, I'll be happy to provide the workflow.