Aug 252017

(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.

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:

  1. Checks to make sure the above requirements are met
  2. Loads functions and variables (you will have to edit some of them for your environment – see the script for more info)
  3. Gets a list of all vhd/vhdx files in the root of your profile share
  4. Runs a for each loop
    1. Tests to see if the vhd file is currently locked (in use)
      1. 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)
      2. If no then it will move on
    2. Tries to mount the vhd in read only mode
      1. If it fails it will send you an alert email and end the script as something is not right
      2. If it mounts then the script moves on
    3. Tries to optimize the vhd file (compact)
      1. Gets the original size in MB, size after compact in MB, computes the total reduction in MB, and notes failure/success
    4. Tries to dismount the vhd
      1. If it fails it will send you an alert email and end the script
  5. Once finished it will email you a report like the one below (names, paths, and sids are masked obviously)

Here is the script

  13 Responses to “FSLogix VHD/VHDX Profile Compacting Script”

  1. Very nice, David. Thanks for posting this!

  2. […] Script to compact FSLogix VHD/VHDX files – CTA David Ott […]

  3. This is great, thanks. I’m having this exact same issue. I’ll try out this method and report back.

  4. […] As mentioned above I found the script from the creator David Ott and you can find the original post with script here! […]

  5. […] FSLogix VHD/VHDX Profile Compacting Script by David […]

  6. […] FSLogix VHD/VHDX Profile Compacting Script by David […]

  7. […] post is an updated version of my original profile compacting script ( I wrote it using Powershell Studio and converted it into an executable. This version does not […]

  8. […] Compaction – See FSLogix VHD/VHDX Profile Compacting Script by David […]

  9. […] Compaction – See FSLogix VHD/VHDX Profile Compacting Script by David […]

  10. Hi David, thanks for creating the script. Is ist possible to run it on a Windows Server 2016/19 instead of Win. 10?

  11. 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

  12. […] A tool for compacting FSLogix profiles has been written by David Ott and is available at […]

  13. Hello,

    it would be nice if there was also an email notification function 🙂

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">



This site uses Akismet to reduce spam. Learn how your comment data is processed.