Introduction
This article stems from a query shared in the Modern Endpoint Management LinkedIn group concerning the synchronization and backup of user Teams backgrounds to OneDrive. As I frequently work with Teams, I found this issue intriguing and sought a solution. Teams backgrounds are saved in the user’s %appdata% directory, making it essential to sync the %appdata%\Microsoft\Teams\Backgrounds\Uploads folder to a designated location in OneDrive. The next step was ensuring this applies to any other PC the users access, allowing their backgrounds to accompany them. Initially, I followed Microsoft’s guide to establish a symbolic link — Can’t synchronize OneDrive files and folders from a local file location other than the default OneDrive path (microsoft.com). Although it worked initially, the approach failed on the second PC. The root issue was that you cannot create a junction link if a directory already exists. The initial deployment worked on PC1 and successfully created a junction from the %appdata%\Microsoft\Teams\Backgrounds\Uploads folder to a folder named Teamsbackgrounds in OneDrive. However, OneDrive wouldn’t sync the files to the %appdata%\Microsoft\Teams\Backgrounds\Uploads folder on PC2 due to the existing directory in OneDrive. After spending hours attempting to resolve this, I determined I needed to rethink my strategy.
I got creative with my solution. Given that many clients I work with utilize Windows 10 Pro, I aimed to avoid proactive remediations for those lacking the necessary licenses. After extensive testing, I developed a solution that meets my original goal, albeit through a more traditional approach. Throughout this process, I discovered valuable insights on deploying scheduled tasks via Intune. A separate blog post emerged, detailing how to deploy scheduled tasks with Intune here. In summary, we plan to deploy two Win32 apps aimed at a user group. The initial app will create the %appdata%\Microsoft\Teams\Backgrounds\Uploads and %userprofile%\OneDrive – orgname\TeamsBackgrounds directories if they do not currently exist. This step is crucial because the uploads directory is by default absent until a user saves a custom background. Thus, if a user is signing into a PC for the first time, it won’t be there, necessitating its creation by the app. The second Win32 app, dependent on the first, performs two actions: it copies a robocopy script and VB script to the c:\temp directory and sets up a scheduled task to facilitate regular two-way file copies between the two folders created by the first app. While it’s true that OneDrive isn’t “natively” syncing the directories, the objectives are ultimately met, and I was unable to devise a better solution. Additionally, this guide assumes you have applied a configuration profile to automatically establish OneDrive sync for your users.
Win32 App #1
The first step involves creating the required directories if they do not exist. Ensure you modify the path to align with your organization’s OneDrive in the script. If you’re unsure about the path, the easiest method is to check a machine with an already configured OneDrive sync. Open Windows Explorer and examine your OneDrive sync locations in the left pane. The default path should usually be c:\users\username\OneDrive – org. This is demonstrated in the screenshot below.
$uploads = "c:\users\$env:UserName\appdata\roaming\Microsoft\Teams\Backgrounds\Uploads"
$teamsbackgrounds = "c:\users\$env:UserName\OneDrive - changeme\Teamsbackgrounds"
New-Item $uploads -ItemType Directory -Force
New-Item $teamsbackgrounds -ItemType Directory -Force

Wrap the script as a Win32 app and configure it within Intune. You can download the IntuneWinAppUtil here.

Create a new Win32 app in your tenant and import the intunewin file. Name the app whatever you’d prefer:

I utilize the same install command for the uninstall command since these directories are harmless to retain. Remember to select install for USER.

Define a requirement rule and create two detection rules to check for the two directories we are establishing – %appdata%\Microsoft\Teams\Backgrounds\Uploads and c:\users\%username%\onedrive – orgname\Teamsbackgrounds.


You might optionally want to set a dependency on your Teams installation if you’re rolling it out as an Intune app. Complete the remaining steps and assign it to a user group. The app should commence deployment after the next check-in. Below is a glimpse of my test user who logged into three devices:

Win32 App #2
This application generates c:\temp if it does not already exist, copies a robocopy and VB script into that directory, and registers a scheduled task with two triggers that execute the two-way robocopy script:
Trigger 1: Activates 10 minutes after the task is created. This provides adequate time for the OneDrive sync settings to take effect.
Trigger 2: Activates 10 minutes after a user logs in, and then again every hour (executed under the logged-on user). This ensures that the OneDrive sync settings take effect for users logging into a machine for the first time, even if the task is already created.
All scripts are outlined below and are available on GitHub here. There is also an uninstall script for removing the scheduled task if necessary. For the scheduled task, you can utilize my XML file, or create your own task with your specific settings (details can be found here). Ensure you modify the robocopy script to reflect your OneDrive organization’s path. Additionally, there’s a VBS file. After troubleshooting for a while, I discovered that the command window appeared on the user’s screen for 1-2 seconds during the execution of the task and robocopy script. To suppress this, I found a VBS script online, designed to run the cmd file without any window or user interaction.
VBS Script:
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run chr(34) & "C:\Temp\TeamsBackgroundSync.cmd" & Chr(34), 0, True
Set WshShell = Nothing
Robocopy script:
robocopy %appdata%\Microsoft\Teams\Backgrounds\Uploads\ "%userprofile%\OneDrive - orgname\TeamsBackgrounds\ " /XO
robocopy "%userprofile%\OneDrive - orgname\TeamsBackgrounds\ " %appdata%\Microsoft\Teams\Backgrounds\Uploads\ /XO
Script for creating directory, copying files, and establishing scheduled task:
$tempdir = "c:\temp"
New-Item $tempdir -ItemType Directory -Force
Copy-Item ".\SilentCMD.vbs" -Destination $tempdir -Force
Copy-Item ".\TeamsBackgroundSync.cmd" -Destination $tempdir -Force
Register-ScheduledTask -xml (Get-Content '.\TeamsBackgroundSync.xml' | Out-String) -TaskName "TeamsBackgroundSync" -Force
Removal Script:
Unregister-ScheduledTask -TaskName TeamsBackgroundSync -Confirm:$false
Remove-Item -Path C:\temp\SilentCMD.vbs -Force
Remove-Item -Path C:\temp\TeamsBackgroundSync.cmd -Force
Below are details regarding the scheduled task, which can be customized to your preferences. You may export it as an XML once you have it set up as you desire. Additional guidance on deploying scheduled tasks via Intune can be found in my previous post linked above.

The triggers are set to execute the script 10 minutes after user logon, and then repeat every hour throughout the day.

The additional trigger activates the task 10 minutes after it is created/modified:

The action is to execute our VBS file, which runs the robocopy script silently:

Bundle all four scripts along with the XML into the same directory and encapsulate them as an intunewin package, using ImportTask.ps1 as the setup file:

Establish another Win32 app and configure it accordingly, or modify it as per your requirements:

The install and uninstall commands refer to two PowerShell scripts. It’s optimal to install this app as a system:

We will set up three detection rules. One will ensure the scheduled task exists, while the other two will confirm the presence of the robocopy script and VBS script. All scheduled tasks are stored as XML files (without the file extension) in c:\windows\system32\tasks\



Set a dependency for this app on the previous app to ensure that the necessary directories exist:

Complete the remaining steps to create the app and assign it to your user group. After waiting for your apps to deploy, user backgrounds should begin syncing 😊. Below you will find numerous additional screenshots post-deployment, and after executing the task.
Post Deployment
Our Win32 Sync App completes successfully:

The scheduled task successfully created:

Task triggers as configured earlier:

The action performed by our robocopy script runs silently, invoked by the VBS script:

The task registers at 6:12 AM, activating 10 minutes later at 6:22 AM:

Here are two machines illustrating how this functions with the same user signed into each. Machine A on the left logged in a few seconds before Machine B on the right, resulting in tasks that are separated by about 5-10 seconds. The user initially had two backgrounds synced to OneDrive (Metallica and Motorhead) and added two more on Machine A (Ozzy and Pink Floyd). As the task runs, the sync occurs clockwise, starting from the lower left and concluding at the lower right. The Teams “uploads” folder with backgrounds from Machine A synchronizes with OneDrive, and OneDrive sync on Machine B recognizes the new images. Once the task runs on Machine B, it pulls all images from OneDrive into the Teams backgrounds uploads folder on Machine B (shown in the lower right).
