[HOWTO] Sync OneDrive on Server even if Windows User not logged in
In a project for one of our customers we used Microsoft OneDrive for data synchronisation. The data gets collected on a tablet and the folder containing the data will be […]
Audit and Consulting of Information Systems and Business Processes
In a project for one of our customers we used Microsoft OneDrive for data synchronisation. The data gets collected on a tablet and the folder containing the data will be […]
In a project for one of our customers we used Microsoft OneDrive for data synchronisation. The data gets collected on a tablet and the folder containing the data will be synchronized with OneDrive. On the other side there is a Windows Server that needs to move the data from OneDrive to a network drive. To get the data from OneDrive I installed the OneDrive Client Version 2016 (Build 17.3.6943.0625
) on the Server. Furthermore I created a scheduled task that executes a PowerShell script to copy the files from the synchronized OneDrive folder to the network drive. Unfortunately OneDrive only runs synchronization if the user, the OneDrive client was installed with, is logged in to Windows. As the user does not log in to the server regularly and because there is no possibilty to reconfigure OneDrive to allow synchronization even if the user is not logged in, I had to find a way to regularly synchronize the OneDrive folder. After a few tries I succeeded by creating a scheduled task that starts and stops OneDrive.exe on a given schedule.
The scheduled task was created as follows.
might need to use this – thanks
I assume that you also set the script to run under the users credentials, or does OneDrive sync all accounts as long as a any single user is running OneDrive.exe at the time?
I was also wondering how you knew that a sync wasn’t in progress when copying from the OneDrive folder on the server to the Network Drive? For example if a large file update/upload was in progress how did you ensure your script waited for that Sync to finish before copying the contents over to the network?
Hi Daniel
Your assumption is true. We configured the task to run using the account of the user we set up OneDrive for.
Concerning your second question I have to clarify, that data gets collected throughout the working day by an employee and moving the files from OneDrive folder to the Network Drive takes place every night at 01:00 AM. Therefore there is enough time for synchronization between return to the office and start of the moving task.
In the meantime we replaced OneDrive with Azure Files because the solution described in this blog post stopped working with newer versions of OneDrive…
Add arguments: /background
Is adding this argument verified to work? I wasn’t able to get it working.
Note that this only worked with OneDrive Client version 2016 (build 17.3.6943.0625)
This does not work I am trying to use this on windows server 2012 r2
Also I a unable to set the user I have to use system don’t know why
It only worked up to the version mentioned in the blog post. In the meantime we replaced OneDrive with Azure Files because the solution described in this blog post stopped working with newer versions of OneDrive…
It’s Working good. Thanks
might need to use this=
Why did you stop and restart each hour? Why not start, say, daily and keep it running?
We started and stopped the scheduled task every hour to ensure, that sync really takes place.
In the meantime we replaced OneDrive with Azure Files because the solution described in this blog post stopped working with newer versions of OneDrive…