The introduction of Onedrive For Business and Known Folder Moves has allowed for businesses to move from the traditional methods of redirected profiles and the limitations that come with them.
There are two primary advantages of moving or redirecting Windows known folders (Desktop, Documents, Pictures, Screenshots, and Camera Roll) to Microsoft OneDrive for the users in your domain:
- Your users can continue using the folders they’re familiar with. They don’t have to change their daily work habits to save files to OneDrive.
- Saving files to OneDrive backs up your users’ data in the cloud and gives them access to their files from any device.
Unfortunately, OneDrive Known folder move sometimes works a little too well. And the solution that’s provided in this post will help you for when you’re faced with the scenario listed below.
When you log into a computer for the first time Microsoft Edge and Microsoft Teams creates a .lnk file as a shortcut to the applications. Onedrive will then do what it’s designed to do and upload these .lnk files to your OneDrive profile.
Now, when logging in to a second computer for the first time the .lnk files will be created, and once your OneDrive profile is loaded and your files have synced it will download the shortcuts that were created from the first pc. This causes shortcut copies to be created on the users desktop.
To remedy this I have created a powershell script to remove these shortcuts. What the script does is
- It will set the profile path to the users desktop within their OneDrive profile.
- It will look for all files that match “Microsoft Edge – copy*.lnk” or “Microsoft Teams – copy*.lnk”
- It will remove the shortcuts
$Desktop = [Environment]::GetFolderPath("Desktop") Get-ChildItem -Path $Desktop -Filter *.lnk | Where {$_.Name -like "Microsoft Edge - Copy*.lnk" -or $_.Name -like "Microsoft Teams - Copy*.lnk"} | Remove-Item -Force -ErrorAction SilentlyContinue
You can then take this script and deploy it as a startup or login script via GPO to resolve this for your affected users.
I hope that you find this post useful, if you have any comments or suggestions feel free to comment.
Thanks.
During a clean enrollment, won t the script run too soon? In my experience, OneDrive is only being configured after user logon, after a few moments. When pushing this script alongside a new deployment, it will likely run before onedrive is configured, which means the copy files will not be present and won t be deleted. A solution for this would be a do-until loop which checks for the presence of onedrive over and over again, and if it detects it, continue with the rest of the script to remove the additional shortcuts.
Hey there,
The script runs as a logon script so it will run on each logon, therefore it doesnt matter whether it runs too early as it will just run again on the next user logon.
Thanks, Omar.
I cannot believe this is still an issue, 2 years later…
I have custom applications that install per-user and users that login to multiple devices, so it’s going to create this shortcut for each device they login to. I might try the script you’ve got here, but just wanted to voice my displeasure. Come on, Microsoft!