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

  1. Open Task Scheduler
  2. Action > Create Task ...
  3. General configuration
  4. Create trigger
  5. Create new action

    Program/script: C:\Users\USERNAME\AppData\Local\Microsoft\OneDrive\OneDrive.exe

  6. Configure settings

Comments

  1. Peter says:

    might need to use this – thanks

  2. Daniel Harris says:

    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…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: