Microsoft OneDrive is part of Office 365 and has become more popular with companies. This article is about how to handle Microsoft OneDrive within a virtual desktop infrastructure. The focus is mainly for multi-user environments with Server 2019 or Windows 10 VWD but could be used within other scenarios.
With OneDrive, all users' files are in the Microsoft cloud but synced down to the user profile. Therefore, OneDrive can fill up a user's profile fast and would require more local or on-prem storage again. In addition, users are changing the end device all the time, which impacts the logon time. How to make sense out of OneDrive in a VDI environment is what I will try to explain.
Microsoft OneDrive within VDI Problem
Let's start with that OneDrive was designed for single-user systems and not for multi-user systems, which is an issue by itself. VDI is very common these days, and of course, customers want to use OneDrive on those virtual desktops as well. OneDrive synchronizes data between the user device and the Microsoft cloud storage. Customers move all their data into the cloud to overcome the growing storage requirements in the on-prem data center. In the beginning, OneDrive downloaded all or selective user data to the user's device.
That way, the data is back in the on-prem data center, just spread over several devices. In a VDI environment, the data is stored in the user profile and finally on a file server that requires storage again. That way, nothing is accomplished besides the fact that users spread out the data even more.
Realizing the problem, Microsoft introduced the "Files on Demand" feature. With files on-demand, no file is synced automatically and instead only downloaded when the user requests the file. That's great because the amount of data that is re-downloaded from the cloud is reduced. By the way, files on-demand requires at least Windows Server 2019 or Windows 10 with the new file attributes for cloud content. However, users might quickly require all their files, and again, the local storage is loaded with all the OneDrive files and blows up the profile. So to keep the logon time low, you should use a virtual disk attached at logon like with FSLogix or Citrix UPM container disk. Nevertheless, this will require storage space again.
Another piece to solve the problem is Microsoft Storage Sense. With Storage Sense, cloud content can be automatically released, deleted locally but stays within the cloud. OneDrive option to do the same is "Free up space" when you right-click a downloaded file.
With Server 2019, you have to use a PoSh script to configure the per-user policies for Storage Sense. The minimum you can set is one day to keep cloud content, and the clean-up process is also done once a day by the system. Within VDI, this is a problem again! The clean-up runs once a day, and you don't know when! With users log in and log off at least once a day, it may be hard to hit the system's clean-up time. Therefore, the clean-up might never run for a user, or when it finally runs, the virtual disk has grown and must be compressed.
In the end, we haven't won anything with Storage Sense and files on-demand. Now you can delete the OneDrive content at logoff or don't write it back like with FSLogix redirection.xml. Most often, deleting the OneDrive content ends with OneDrive crashing at start-up. So I cannot recommend deleting the OneDrive folder or content.
The OneDrive VDI workaround
Now what we need would be that Storage Sense would run at user logoff and release all cloud content immediately! Unfortunately, this is not an option at the moment. Instead, a Storage Sense option would be: "Remove files at logoff" and not after one day. Some suggest running cleanmgr.exe /autoclean /d
to free up space, but this doesn't work per user.
The solution is to run a Powershell script at logoff and you don't even have to setup Storage Sense! The script loops through the OneDrive folder of the user and only files not marked to stay on the device or URL files are removed and therefore will not be roamed within the profile. This is actually what is required in a VDI envrionment.
The Powershell script can be executed through a user logoff script within group policy or with Citrix Workspace Environment Manager after version 1912. Find the download link below.
The downside might be a short high CPU consumption when the script runs. Also, you can not use the FSLogix office container because they are detached immediately at logoff, and therefore, the script would not find any OneDrive folder or content.
The mysterious OneDrive issue
Even after some years now, also outside VDI environments, one major issue with OneDrive is still unsolved! For an unknown reason, users' files are moved into the recycle bin without doing anything. If you have a solution for that issue, please let me know!
PowerShell Download Link
For the download you have to supply your name and email address. If you don't want me to save the data, then send me an eMail or don't download the file.
Download: free-up-space.zip
Let me know what you think about my way of using OneDrive!