Update: a more lightweight/simpler version of this script is available here: https://www.lieben.nu/liebensraum/2021/09/redirecting-anything-to-onedrive-for-business/
In the post-Onedrivemapper era where we have Files On Demand, there is still room for improvement in client side configuration of Onedrive for Business. Onedrive Known Folders isn’t up to par yet, doesn’t support any customization and there are situations where I want to be able to redirect local folders to other places than Onedrive like Teams or Sharepoint.
Therefore I present to you “Invoke-O4BAutoMount“; the ultimate Onedrive/Sharepoint/Teams sync and redirect solution in modern workplace scenario’s, no WebDav, just the NSG Onedrive Client and native Intune Management Extension:
- Single PS script
- User does NOT have to be an Admin
- Per special folder configuration of redirection settings
- Extra (symlink) redirection for ANY folder (specific appdata subfolders anyone?)
- Automatically runs at logon and/or at specified intervals
- Can be unassigned (removing a user from the target group in Intune stops the script from running)
- Can redirect to subfolders, even nested
- Handles automatic creation of any folders
- Supports variables in paths
- Registers Environment Variables for the new locations if you configure it to
- Can hide target folders (appdata likes to hide)
- Multi-user support (Windows Virtual Desktop / Server 2019)
How to use in 8 easy steps:
1. Configure the tenant ID and how often you want to script to run:
2. Then get the ODOpen URL of any libraries you wish to sync:
3. paste the URL into the script in the syncUrl section and configure the site and list titles:
4. if you only need Onedrive and don’t want to sync any sharepoint/teams libraries, configure like this:
5. Pick which folders you want to redirect, and where you want to redirect them to:
6. Configure any special folders that normally cannot be redirected
7. Upload to Intune as a PowerShell script:
8. Deploy to your users (you can also deploy to machines, but then you need to set autoRerunMinutes to > 0 and it might not run at logon)
This script assumes you’ve already Configured Onedrive to automatically log the user in and I strongly recommend to run Onedrive in Per Machine Mode for faster config.
I haven’t extensively tested running this script when multiple users are active on a device at the same time (ie: citrix, wvd, remoteapp); I’d love to hear about your results!
Thanks and inspiration
Michael Mardahl for giving me the ODOPEN and IME hack examples
Aaron Parker for writing on Folder Redirection with PowerShell
Justin Murray for showing me how to impersonate another user
Per Larsen for writing on silent config / admx stuff regarding Onedrive
Olivier Kieselbach for his three deep dives on the Intune Management Extension
2021/9: I’ve added a more lightweight version that supports redirection only (with custom PS commands supported). The redirections have to be configured through the registry, see the code here.
As always, this is a free script and no guarantees are given, use at your own risk.
c:\\users\\appdata\\local\\temp\\Invoke-O4BAutoMount.log for the user portion.
C:\\Windows\\Temp\\Invoke-O4BAutoMount.log for the SYSTEM portion
If the script isn’t running at all (no log file), check the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IntuneManagementExtension\Policies subkeys for error info from the script. Make sure the config section of the script is correct or it won’t run.
If it isn’t as running as frequently as you like, you may be getting throttled. Don’t run more frequently than hourly (per account).