Forum Discussion
O365 Batch Deployment -- OneDrive Auto Configuration
- Feb 14, 2023
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:
- 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.
- Open Command Prompt: Open the Command Prompt as an administrator on the new PC.
- Run the following command:
OneDrive.exe /configurepolicies "{\"FilesOnDemandEnabled\":true,\"KnownFolderMoveEnabled\":true,\"KnownFolders\":[{\"Name\":\"Desktop\",\"Target\":\"OneDrive\"},{\"Name\":\"Documents\",\"Target\":\"OneDrive\"}]}"
- 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.
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:
- 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.
- Open Command Prompt: Open the Command Prompt as an administrator on the new PC.
- Run the following command:
OneDrive.exe /configurepolicies "{\"FilesOnDemandEnabled\":true,\"KnownFolderMoveEnabled\":true,\"KnownFolders\":[{\"Name\":\"Desktop\",\"Target\":\"OneDrive\"},{\"Name\":\"Documents\",\"Target\":\"OneDrive\"}]}"
- 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.
- AlltheBytesFeb 15, 2023Copper 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?