Forum Discussion

AlltheBytes's avatar
AlltheBytes
Copper Contributor
Feb 14, 2023
Solved

O365 Batch Deployment -- OneDrive Auto Configuration

Hello all,

 

I have been working on a batch script that will deploy all of my company's "standard" programs to new PC's as they come across my desk. It is coming along nicely, and I need to configure OneDrive so that it is enabled (I have done this through the Office Deployment tools and a custom XML file), and also only syncs the user's Desktop and Documents folder to OneDrive automatically. Is there a way to automate this, or will I have to go into OneDrive user preferences and set it that way for every new user?

Command Prompt/batch solutions are very much preferred, if possible.

 

Thanks all!

  • AlltheBytes

    You can automate the configuration of OneDrive to sync only the user's Desktop and Documents folder by using the OneDrive client's command-line interface (CLI). You can use the CLI in a batch script to configure OneDrive for each user.

    Here's an example of how I would do this:

     

    1. Download the OneDrive client: You'll need to download the OneDrive client for your operating system if it is not already installed on the new PC's.
    2. Open Command Prompt: Open the Command Prompt as an administrator on the new PC.
    3. Run the following command:

      OneDrive.exe /configurepolicies "{\"FilesOnDemandEnabled\":true,\"KnownFolderMoveEnabled\":true,\"KnownFolders\":[{\"Name\":\"Desktop\",\"Target\":\"OneDrive\"},{\"Name\":\"Documents\",\"Target\":\"OneDrive\"}]}"


    4. Add the command to your batch script: You can add this command to your batch script so that it   runs automatically when you deploy OneDrive and the other "standard" programs to the new PC's.

    By using the OneDrive CLI in a batch script, you can automate the configuration of OneDrive to sync only the user's Desktop and Documents folder, saving you time and effort. Keep in mind that OneDrive may need to be restarted after the configuration is applied for the changes to take effect.

     

2 Replies

  • Mark_Albin's avatar
    Mark_Albin
    Brass Contributor

    AlltheBytes

    You can automate the configuration of OneDrive to sync only the user's Desktop and Documents folder by using the OneDrive client's command-line interface (CLI). You can use the CLI in a batch script to configure OneDrive for each user.

    Here's an example of how I would do this:

     

    1. Download the OneDrive client: You'll need to download the OneDrive client for your operating system if it is not already installed on the new PC's.
    2. Open Command Prompt: Open the Command Prompt as an administrator on the new PC.
    3. Run the following command:

      OneDrive.exe /configurepolicies "{\"FilesOnDemandEnabled\":true,\"KnownFolderMoveEnabled\":true,\"KnownFolders\":[{\"Name\":\"Desktop\",\"Target\":\"OneDrive\"},{\"Name\":\"Documents\",\"Target\":\"OneDrive\"}]}"


    4. Add the command to your batch script: You can add this command to your batch script so that it   runs automatically when you deploy OneDrive and the other "standard" programs to the new PC's.

    By using the OneDrive CLI in a batch script, you can automate the configuration of OneDrive to sync only the user's Desktop and Documents folder, saving you time and effort. Keep in mind that OneDrive may need to be restarted after the configuration is applied for the changes to take effect.

     

    • AlltheBytes's avatar
      AlltheBytes
      Copper Contributor

      Thanks so much for your help Mark_Albin! I appreciate the insight.

      My only issue with this command is, when I try to run it in my script, which is running from an elevated Command Prompt, it gives me an error, stating that OneDrive must be run without administrative rights. However, when I tried to replicate this on my own machine, it worked. The only differences between the two environments and the way I ran them are

      1: I am logged in as myself (a Domain admin) on my own machine, but a local admin account (we'll call him "Install") runs the script on all new machines, as that's the first account we set up out of the box. 

      2: I noticed that OneDrive installed to Program Files (x86) on my new machine, but on my own machine it was apparently just in Program Files. Please keep in mind, the new machine is not attached to the domain at this point in the process, so I would think my authority as a domain admin wouldn't matter yet.

       

      Do you have any insight?

       

       

Resources