Dynamic VHDX files are a lot like that storage unit you rented five years ago. You keep tossing stuff in, it keeps expanding to fit everything, and even after you clean half of it out, you’re still paying for the full footprint. When those FSLogix profiles live on Azure Files, that leftover empty space turns into real money on your monthly bill.
The good news is you don’t have to live with bloated profile containers. FSLogix has built-in compaction that runs automatically at sign-out, and it also ships with frx.exe if you need to convert older .vhd files or rebuild a stubborn container from scratch.
How FSLogix Compaction Actually Works
Starting in FSLogix 2210, Microsoft turned on automatic VHD Disk Compaction by default, as detailed in Microsoft Learn’s VHD Disk Compaction documentation. Every time a user signs out, FSLogix checks their container and shrinks it if there is enough empty space to justify the work.
Contrary to popular belief, this works on both .vhd and .vhdx files, as long as they are dynamically expanding. Fixed-size disks will never shrink, and FSLogix will skip them and log Event ID 61 in Event Viewer.
Even with dynamic disks, FSLogix won’t compact a profile unless it meets three rules:
- The container’s consumed size on disk is greater than 1 GB.
- At least 20% of that consumed space is reclaimable white space.
- The Windows Optimize Drives (
defragsvc) and Microsoft Storage Spaces SMP (smphost) services are set to Manual or Automatic (never Disabled).
If your session hosts have defragsvc disabled as part of a Golden Image hardening script, automatic compaction fails silently and logs Event ID 60. That’s usually the culprit when profiles refuse to shrink, and you can check Microsoft Learn’s Troubleshooting VHD Disk Compaction guide for the full list of event codes.
Azure Files Billing: Standard vs. Premium
Before you spend an afternoon shrinking profiles, make sure you know how your Azure Files tier actually bills you.
| Azure Files Tier | Billing Model | Effect of Shrinking VHDX Files |
|---|---|---|
| Standard (HDD) | Pay per consumed GiB + transactions | Directly lowers your monthly storage bill |
| Premium (SSD) | Pay for provisioned share capacity | Prevents premature share expansion; bill only drops if you manually shrink the share |
Prerequisites
Make sure you have these ready before touching any production profiles:
- FSLogix Apps version 2210 (
2.9.8361.52326) or newer installed on your session hosts. - An administrative machine or session host with access to the Azure Files SMB share.
- Confirmation that the target user is completely signed out so their VHDX isn’t locked.
- A backup or snapshot of your Azure File share before running manual migrations or bulk shrink scripts.
Verifying Automatic Compaction on Session Hosts
- Open an elevated PowerShell prompt on your session host or Golden Image.
- Check that the required Windows services aren’t disabled. The command below sets both
defragsvcandsmphostto Manual so FSLogix can call the Windows partition API at sign-out.
Set-Service -Name defragsvc -StartupType Manual
Set-Service -Name smphost -StartupType Manual
Code language: PowerShell (powershell)
- Verify that
VHDCompactDiskisn’t explicitly disabled in the registry. By default it’s enabled, so you only need to set this if a Group Policy Object (GPO) or old script turned it off.
Set-ItemProperty `
-Path "HKLM:\SOFTWARE\FSLogix\Apps" `
-Name "VHDCompactDisk" `
-Value 1 `
-Type DWord
Code language: PowerShell (powershell)
- Check compaction results after a user signs out by opening Event Viewer and navigating to Applications and Services Logs > Microsoft > FSLogix > Apps > Operational. Look for Event ID
57to confirm the disk was compacted and see how much space you got back.
Heads up: If you use FSLogix Cloud Cache or differencing disks (
ProfileType = 3), automatic compaction evaluates the tiny differencing disk instead of the parent container, so it will often skip compaction. Compaction also has a five-minute timeout per sign-out, so huge containers might take more than one logoff to finish shrinking.
Bulk Shrinking Offline with Invoke-FslShrinkDisk
If you’re staring at dozens of bloated profiles on an Azure Files share and don’t want to wait around for every user to sign out, check out Jim Moyle’s Invoke-FslShrinkDisk script on GitHub. It’s an open-source, multi-threaded PowerShell script maintained under the official FSLogix GitHub organization.
Instead of rebuilding containers from scratch, Invoke-FslShrinkDisk mounts each VHD or VHDX in place, defragments the volume, and compacts the empty white space down to the smallest possible footprint. It works great as a scheduled off-hours cleanup job when users are signed off.
Warning: Do not run
Invoke-FslShrinkDiskif your environment uses FSLogix Cloud Cache. Modifying the virtual disks out-of-band behind Cloud Cache’s back can cause sync issues or corruption across your replica storage locations.
Converting and Shrinking Manually with frx.exe
If you have legacy .vhd containers you want to convert to .vhdx, or a stubborn container that still won’t shrink, you can use frx.exe. As covered in Microsoft Learn’s frx command-line utility reference, FSLogix doesn’t have a direct compact or shrink flag, so you use migrate-vhd instead. It creates a brand-new dynamic VHDX and mirrors only the active data into it, leaving the empty white space behind. While I haven’t personally run frx migrate-vhd in my own lab, I have helped other admins run it and have seen it work well.
- Confirm the user is logged off and their container isn’t mounted on any session host.
- Open an elevated Command Prompt on a machine with
FSLogix Appsinstalled and runfrx.exe migrate-vhd. The example below converts an old.vhdinto a new 30 GB dynamic.vhdxwith a4096sector size and verbose logging.
"C:\Program Files\FSLogix\Apps\frx.exe" migrate-vhd ^
-src "\\<storage-account>.file.core.windows.net\<share>\<user_sid>\Profile.vhd" ^
-dest "\\<storage-account>.file.core.windows.net\<share>\<user_sid>\Profile_new.vhdx" ^
-size-mbs 30720 ^
-dynamic 1 ^
-vhdx-sector-size 4096 ^
-verbose
Code language: DOS .bat (dos)
Warning: Because
migrate-vhdcreates a brand-new file, make sure the new.vhdxkeeps the proper New Technology File System (NTFS) and Server Message Block (SMB) permissions for the user’s Security Identifier (SID). If the user doesn’t own the new file, their next sign-in will fail to mount the profile.
- Once the migration finishes and you’ve verified the new file size, rename or archive the original container and rename
Profile_new.vhdxto match your FSLogix naming convention. - Have the user sign back in and verify their profile loads cleanly before deleting the old file.
Summary
Keeping FSLogix containers lean on Azure Files comes down to making sure automatic compaction isn’t blocked by disabled Windows services, using Invoke-FslShrinkDisk for scheduled bulk cleanups, and falling back to frx.exe migrate-vhd when you need to convert legacy .vhd files. Take an Azure Files snapshot before you start shrinking or migrating containers, and check your Event Viewer logs after a few sign-outs to verify the space is actually coming back. Let me know how you make out!
Note: I haven’t personally run Invoke-FslShrinkDisk or frx.exe migrate-vhd directly in my own lab, though I have helped other admins run migrate-vhd successfully. Test any command or script on a single non-production profile first before running it across your share.