I recently switched from Citrix Profile Management to FSLogix! For those of you who do not know how it works… it mounts a virtual hard drive at the C:\Users\%UserName% folder for each user who connects. A huge advantage to this is that it is not copying the profile in at logon (or out at logoff), which greatly reduces logon times. Depending on how you have things setup you can literally (not figuratively) expect logon times of around 15 seconds reported in director no matter how your users decide to bloat their profiles.
There is one “problem” with dynamic vhd/vhdx profiles… they don’t shrink on their own. For instance, if you were to copy a 4GB file into a dynamic vhd file you would obviously see it grow by about that much. If you delete that 4GB file the vhd stays the same size! This isn’t really that big of a deal to me, but it might be to my storage administrator.
I wrote a script to compact the vhd profiles not in use.
Windows 10 – Powershell v5
Hyper-V module (Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All) – reboot required
Powershell run as Administrator
What this script does:
- Checks to make sure the above requirements are met
- Loads functions and variables (you will have to edit some of them for your environment – see the script for more info)
- Gets a list of all vhd/vhdx files in the root of your profile share
Runs a for each loop
Tests to see if the vhd file is currently locked (in use)
- If yes it will display a message on your screen saying it is locked and that it is being skipped (in the report the Success column will be marked with locked)
- If no then it will move on
Tries to mount the vhd in read only mode
- If it fails it will send you an alert email and end the script as something is not right
- If it mounts then the script moves on
Tries to optimize the vhd file (compact)
- Gets the original size in MB, size after compact in MB, computes the total reduction in MB, and notes failure/success
Tries to dismount the vhd
- If it fails it will send you an alert email and end the script
- Once finished it will email you a report like the one below (names, paths, and sids are masked obviously)
Here is the script