User Profile Disks (UPD) is a new feature of Remote Desktop Services in Windows Server 2012. User Profile Disks is an alternative to roaming profiles and folder redirection in the RDS scenarios. The point of UPD is that user and apps data (i. e., a user profile) are stored as a separate VHDX disk on dedicated file on the network shared folder. This virtual disk is mounted to the user session as soon as the user signs in to the RDS server, and unmounted when he logs out (all changes to the user profile are saved to the vhdx disk).
In this article, we’ll describe how to configure and use User Profile Disks on a server with Remote Desktop Services role running on Windows Server 2012 / 2012 R2 / 2016.
Configuring User Profile Disks on Windows Server RDS
First of all, it is necessary to create a shared folder on any corporate file server to store user profiles as VHDX disk (if you want to have high availability for UPD disks, you can place UPD files on a clustered file resource). In our example, the path to this folder looks like this: \\rdvh1\DemoLabOficeApp. Servers being a part of RDS collection have to be given full access permission to access this shared folder.
Tip. In a single RDS collection, there can exist only one VHDX profile file for one user. If a user connects to the resources from two different collections, a separate profile disk should be created for each of them.User Profile Disks mode can be enabled and configured in the collection settings of Remote Desktop Services. This mode can be enabled when creating a new collection, or you can come back to it later.
In our example, the collection already exists, so in the Server Manager console, select this collection and in the upper left corner click Tasks -> Edit Properties.

Then in User Profile Disks section check Enable user profile disks, specify the path to the previously created shared folder (\\rdvh1\DemoLabOficeApps) and a maximum profile disk size (let it be 20 GB). Save the changes.

After you saved the changes, make sure that NTFS permissions for Profile Disks folder have been changed. In our case, the collection consists of one RDSH01 server, which is granted full control permission.

Full Control permissions has been granted to the RDSH01 server on the shared folder level.

When adding new RD Session Host servers to the RDS collection, the wizard automatically changes the folder permissions and gives access to the new servers. It is very convenient, since when scaling a terminal farm you don’t need to remember to set permissions for the profile folder.
UPD: User profile as VHDX file
Go to the network shared folder with user profiles. A UVHD-template.vhdx file is now being stored here.

This file is the user profile disk template. When a user logs on to the RDS server for the first time, this template is copied and renamed as a VHDX file, containing user SID in its name.

Get-ADUser -Identity S-1-5-21-32549751-3956249758-2943215497-23733695

Let’s see what a user profile disk contains. To do it, right-click the VHDX file and select Mount. The UPD disk can only be used in one session on one RDS host (exclusive access). You can’t mount an UPD VHDX disk if the user is currently using it on the RDS server.

As you can see, the VHDX disk contains a set of folders and files of a standard user profile. At logon, a user gets completely transparent access to the data stored in the profile.

On the side of RD Session Host server, a .vhdx user’s file is mounted to the C:\users\<username> and looks like this:

Data is written to the vhdx file in real time. It means that when copying data to a user profile on an RDS server, the size of the vhdx file on the shared storage is incremented immediately.
If the user profile folder already exists in the system, the folder with an old profile is renamed to the <username>-BACKUP-<number>.

The VHDX disk is mounted when the user session starts on a VDI or RDS server. A list of connected UPD disks with profiles can be listed using the mountvol utility.
By default, a User Profile Disk contains all the user profile contents. However, you can exclude certain folders from the list of synchronized directories in the RDS collection settings, or specify that only certain folders should be saved. Thus, all the changes made during the user’s terminal session to the folders in the list of excluded directories are not saved into the VHDX disk on the shared folder.

The second option allows you to configure the saving only the specified directories in the UPD profile.

If necessary, the last option allows you to implement the scenarios for saving the settings of the Start Screen, which are stored in appsfolder.itemdata-ms file. In this example, we have only added the path to \AppData\Local\Microsoft\Windows folder as an additional path to be saved in the UPD.

Resizing User Profile Disks Using PowerShell
You can extend the virtual vhdx drive with the user’s UPD profile using the PowerShell cmdlet Resize-VirtualDisk from the Hyper-V module.
Net use U: \\rdvh1\DemoLabOficeApps
Resize-VHD -Path u:\UVHD-<SID>.vhdx -SizeBytes 40GB
Net use U: /delete
If you want to run the Resize-VHD cmdlet from a desktop with Windows 10, you must install the feature Hyper-V -> Hyper-V Platform -> Hyper-V Services.

Now you need to extend the volume from the GUI of the Disk Management console (Action -> Attach VHD -> Extend volume).

Or use following PowerShell script to automatically extend the vhdx file to the maximum available size:
<#
.Synopsis
This script extend size of VHDX file and resize the disk partition to Max
#>
Param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[alias("Path")]
[string]$vhdxFile,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[alias("Size")]
[int64]$vhdxNewSize
)
begin{
try {
Mount-VHD -Path $vhdxFile -ErrorAction Stop
}
catch {
Write-Error "File $vhdxFile is busy"
Break
}
$vhdx = Get-VHD -Path $vhdxFile
if ($vhdx.Size -ge $vhdxNewSize){
Write-Warning "File $vhdxFile already have this size!"
$vhdx | Dismount-VHD
Break
}
}
process{
Dismount-VHD -Path $vhdxFile
Resize-VHD -Path $vhdxFile -SizeBytes $vhdxNewSize
$vhdxxpart = Mount-VHD -Path $vhdxFile -NoDriveLetter -Passthru | Get-Disk | Get-Partition
$partsize = $vhdxxpart | Get-PartitionSupportedSize
$vhdxxpart | Resize-Partition -Size $partsize.SizeMax
}
end{
Dismount-VHD -Path $vhdxFile
}
Note that you can’t extend the user’s UPD disk with an active RDS session.
To reduce the size of the UPD file (assuming that you deleted the user’s data inside the vhdx file and the file size on the disk is less than the size assigned to it), you can use the commands:
resize-VHD \\rdvh\DemoLabOficeApps\UVHD-<SID>.vhdx –ToMinimumSize
And then:
Optimize-vhd -path \\rdvh1\DemoLabOficeApps\UVHD-<SID>.vhdx -mode full
So, we have discussed the major peculiarities of User Profile Disks in RDS/VDI solutions running Windows Server 2016 and 2012 R2. UPD configuration is much easier than the configuration of roaming profiles or redirected folders. The disks are connected to the RDS collection and can’t be damaged when using the shared profile by several servers (unlike the standard profiles). The User Profile Disks can be stored in SMB shares, CSV, SOFS, SAN or on the local disks. Also, Microsoft notes that the speed of loading the user’s desktop environment in case of using UPD is reduced.
If you are planning to store UPD profiles on DFS servers, be aware that they must have Windows Server 2012 R2 installed. If you are using previous versions of Windows Server, you will get an error:
Unable to enable user disks on rVHDShare. Could not create template VHD. Error Message: The network location "\\woshub.com\namespace\UserProfileDisk" is not available.
Also it is desirable to use the version SMB 3.02 on the file server side (Windows Server 2012 R2) or higher.
Anyway, since User Profile Disks is a relatively new technology, prior to mass UPD implementations, it is recommended to test their work and possible problems in a test environment.