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

13 Comments »

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

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

  3. Pingback: Confluence: RCT
    • 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…

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.