(See the new tool Here)
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.
Requirements:
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
Very nice, David. Thanks for posting this!
[…] Script to compact FSLogix VHD/VHDX files – CTA David Ott […]
This is great, thanks. I’m having this exact same issue. I’ll try out this method and report back.
[…] As mentioned above I found the script from the creator David Ott and you can find the original post with script here! […]
[…] FSLogix VHD/VHDX Profile Compacting Script by David […]
[…] FSLogix VHD/VHDX Profile Compacting Script by David […]
[…] post is an updated version of my original profile compacting script ( http://www.citrixirc.com/?p=829). I wrote it using Powershell Studio and converted it into an executable. This version does not […]
[…] Compaction – See FSLogix VHD/VHDX Profile Compacting Script by David […]
[…] Compaction – See FSLogix VHD/VHDX Profile Compacting Script by David […]
Hi David, thanks for creating the script. Is ist possible to run it on a Windows Server 2016/19 instead of Win. 10?
I hitting the wall since i dont want to run script in win 10 , i want to have it on windows 2016 but it fails then
[…] A tool for compacting FSLogix profiles has been written by David Ott and is available at http://www.citrixirc.com/?p=829 […]
Hello,
it would be nice if there was also an email notification function 🙂