Teams + Known Folder Move = Mess
Endpoint Manager makes it easy to not only deploy the office suite, but to manage policy around the applications as well. There’s often some policies around Outlook and Office in general that are desired, which are available in the ADMX templates. When it comes to OneDrive specifically, most folks opt to enable Silent Configuration and Known Folder Move, which redirects the Documents, Pictures, and Desktop folders to OneDrive for Business.
Most companies like the idea of having Office ready to go before the end user hits the desktop - therefore, we assign Office to the Autopilot Devices Group and block the user during ESP until the Office suite is installed (along with other security-related apps as well). This also ensures that the Teams machine-wide installation completes before the user account signs in, which means we will see the user-based installation complete and launch the application automatically when we arrive at the Desktop.
Around the same time that Teams completes the user install and generates a desktop shortcut, the OneDrive Known Folder Move policy kicks in and redirects the desktop. The only issue here - and this is especially true with those who are constantly testing and re-enrolling devices via Autopilot - is you may end up with multiple copies of the “Microsoft Teams.lnk” shortcut. Especially if you forget to delete these like I do. Look at this mess:
Since I primarily work with IT folks who are testing this heavily for the first time, I figure it would be nice to provide a way to cleanup the icons during test deployments. I created a PowerShell script that generates a reoccurring task for the first 10 minutes of deployment, and it essentially looks for any file names containing “Microsoft Teams -“ in the OneDrive folder path. This one may look a bit odd, as my goal was to do everything within one single script . The other option would have been to wrap three separate files into an intunewin package - that probably would be much prettier, but the scripts tend to hit devices quicker and this needs to hit devices immediately after reaching the desktop.
Take a look at the PowerShell Script below:
The only thing you will want to update are the four line with the file paths - make sure you put the correct path with the OneDrive folder name.
Basically, I perform an initial delete of the files if they already exist, and I include the Add-Type command to be able to enforce a desktop refresh after the delete. I then create a local PowerShell script in C:\Resources with the same commands. This is the part that came out ugly, as I had to work around adding the required single quotes into the file - I would imagine there’s a better way to do this.
I then create an XML file that is used to create a task in task scheduler. I really like this approach with managing tasks - I found that the individual PowerShell commands just don’t present all of the properties that I like to set in a task. I normally have to combine a few commands together to get 80% of the available properties. In this case, I created a trigger that launches the script at task creation, and it repeats every minute for 10 minutes, which should cover the window of the Known Folder Move policy change.
In the end, the files are created and the task is imported and initiated. One thing I noticed is the remaining “Microsoft Teams.lnk” may show a blank image, though this fixes itself when you double click the icon. I would say just remove that as well, and change the line to:
if($icon.Name -like "*Microsoft Teams*")
This may require some additional tweaking depending on the way Office and policies are assigned in your environment, but hopefully this helps with your own testing. Enjoy!