Repair all FSLogix Profiles using PowerShell (or any VHDX files)

While troubleshooting some client AVD issues, I came across something I had not seen before. There were many errors in the FSLogix event log showing that a volume had errors, and this was pointing to user VHDX profile disks. After taking a closer look, this was happening on around half of the user profile disks. You can see the log entries below from event viewer and the FSLogix Profile log:

In Addition, this was causing toast and pop up messages that drives needed to be repaired:

With hundreds of profile disks, it would have been too time consuming to identify the specific profiles that were affected. Instead, I decided to look for a way to scan and repair all the disks. The Repair-Volume PowerShell cmdlet can do what we need (Repair-Volume (Storage) | Microsoft Learn). If we look at the description, we want to use OfflineScanAndFix:

Before we get into how the script works, you’ll need the Hyper-V PowerShell module for this to work. The Mount-VHD and Dismount-DiskImage are part of the Hyper-V module. This module is not available on the PS Gallery. The easiest way to do this is to install the Hyper-V management tools on a workstation or server.

Next, we needed a way to find all VHDX files in a specified share or directory, mount them, scan and repair any errors, dismount, and then move to the next. The resulting script is available on GitHub. The way its currently configured, it will work for any VHDX file, but I used this for FSLogix profile disks. Due to the nature of how FSLogix VHDXs mount to Windows, they won’t receive a drive letter, but they do contain a file system label. So, after mounting the VHDX, the script will first try scanning and repairing the drive based on file system label. If that fails, it will fall back to scanning based on drive letter. Hyper-V disks will use a drive letter when mounted, but don’t contain a file system label. So, it should cover the two most common scenarios. All output is logged to c:\temp\DiskRepair.log. One other reminder – you’ll need to execute this using an account with NTFS permissions to your target directory.

If you take the script as-is and run it, you’ll be prompted first for the target directory containing the VHDX files. This will recurse through all subdirectories

Here is an example of the script running against Hyper-V VHDX files. You can see there is no File System label, so it attempts to mount by drive letter:

And another example of the script against an FSLogix share where its using the FileSystemLabel as the target for the repair-volume cmdlet:

1 thought on “Repair all FSLogix Profiles using PowerShell (or any VHDX files)”

  1. Havіng read this I beⅼieved it was really enlightening.
    I apprecіate you finding the time аnd effort to put this
    article tߋgethеr. I once again find myѕelf spending
    way too much time both reading and commеnting. But so what,
    it was ѕtill worth it!

Comments are closed.