[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


  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…

  3. Onedrive_11-2018 says:

    Add arguments: /background

  4. Note that this only worked with OneDrive Client version 2016 (build 17.3.6943.0625)

  5. Kunal says:

    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…

  6. Kingston says:

    It’s Working good. Thanks

  7. might need to use this=

  8. Tony S says:

    Why did you stop and restart each hour? Why not start, say, daily and keep it running?


  1. ICT – OT RCT Software Sharepoint Sync

    Onedrive client logged in as stevew@rct-global.com

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 )

Connecting to %s

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

%d bloggers like this: