Jul 292019

Update: Added cli functionality.
Update: Added 2nd pass of defrag to fix the profile ballooning issue that sometimes occurs.
Update: Added ability to target profiles over “X” size for compacting
Update 3/31/2020: Fixed a bug that didn’t allow the new tool to run as a scheduled task. Fixed in version 2003.1

This 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 require the Hyper-V powershell module as it uses defrag and diskpart to perform the shrink function.


  1. Administrative rights on the machine running the tool, and read/write to the profiles.
  2. .Net 4.5
  3. Recommend not running from a machine which has any .vhd(x) attached

Instructions/How it works:

  1. The program will remember the last directory selected (via an .ini file – if it exists), or you can click the “…” button at the top left to browse to the root directory of your profile share.
  2. Once a directory is selected it will list all .vhd and .vhdx files along with their current size and their current locked status in descending order by size.
  3. Select the profile(s) you wish to compact (you can select multiple using ctrl and shift+click)
  4. Click the compact button, and the program will process each profile selected one at a time
    1. Checks one more time to make sure the file is not locked
      1. If it is, it will skip on to the next one
    2. Gets the current size again before processing
    3. Attaches the vhd(x) in R/W mode
    4. Finds the first available drive letter it can assign (between D and Z)
    5. Waits 3 seconds before assigning the drive letter (there can be a timing issue if you don’t wait a couple of seconds between mount and drive letter assignment)
    6. Defrags the mounted volume
    7. Detaches and re-attaches as read only
    8. Uses diskpart to compact the vhd(x)
    9. Gets the size of the file post processing
    10. Updates the results pane
  5. After it has run through all the selected profiles it will display the total reduction in MB at the bottom.
  6. Update: To run via CLI simply run from command prompt and add the path to the root profile folder.
    Run against all vhd(x) files ShrinkFSL.exe \\servername\share\
    Run against all vhd(x) files over 5GB
    ShrinkFSL.exe \\servername\share,5120
    1. A log file in csv format will be generated in the same directory that ShrinkFSL is run from. Shrink_MMddyyy_HHmmss.log
    2. If you stop the process make sure you disconnect any vhd(x) file that may be lingering!

You can keep track of the .vhd(x) attaching/detaching via diskmgmt.msc if you want. If for some reason the program hangs up you can click the stop button. It will detect if there is a vhd(x) attached, and detach it. If there is more than one file attached it will not attempt to detach any file. It will instead open diskmgmt.msc for you, so you can perform the cleanup manually (why I recommend not running it on a machine with .vhd(x) files already attached).

Always test new tools in Development/UAT environments prior to running in production! If you have any questions/comments please post here, and I will respond as soon as I can.

Here is a link to the tool (Updated 3/31/2020)

  43 Responses to “FSLogix Profile Compacting Tool”

  1. Thanks David, this is great!!

  2. Simply amazing

  3. Excellent, thank you David. Is there a way that this could be scheduled?

    • I just added cli functionality. ShrinkFSL.exe \\path\to\profiles

    • Hi…Do you have tool or commands to increase container (vhdx) size ?

      • I don’t think he has a tool to do this automatically. However, you can do this with diskpart.

        Open a command window as administrator
        select vdisk file=”d:\blah\somedisk.vhd”
        list vdisk (make sure your disk has a * on it) (If not, select vdisk #)
        expand vdisk maximum=xxxxxxxx (204800 = 200GB)
        attach vdisk
        list disk (make sure your disk has a * on it) (If not, select disk #)
        list volume
        select volume # (Make sure you select your volume)
        extend (Make sure the volume size is correct now)
        detach vdisk

  4. Pretty good tool to use, specially now that FsLogix is kind of free and we will be implementing this on most of our clients.

  5. Amazing! I think many of us will need and use this! Thank you very much for sharing this!

  6. Hi David

    Big thanks for your work. The Tool is for Peoples with GUI Love :). I like the Script more, because i can run it every night. So the CLI Parameter what you wrote is only open ShrinkFSL.exe with the URL to the VHDX Files Root, but not starting it, you must click than “Compact” for your own. So maybe it fails a parameter to compact it than also from CLI automticly!

  7. […] FSLogix Profile Compacting Tool – David Ott […]

  8. I tried this on an O365 Container and it actually grew the vhdx. It said it gained 768mb. Is this expected?

  9. Can you please add the option and/or open source the script so can reset / backup last X profiles?

  10. Hi David,

    Is it possible you could reintroduce the PowerShell script version of this alongside the executable? or provide a link back to the old script you had?

  11. Great tool, thanks!. But I get a bit confused, many .vhdx files gets a – before, and seems to increase in size rather than shrink. Why does some vhdx file get – value as result?

  12. Strange, any body seen any slowness after using this with FSlogix? It take 200+ seconds to login now. I tested it first. So good thing I didnt use this in production yet.

    • The only way this could possibly cause an increased logon time is if the vhd/vhdx remains locked (attached) to the computer running the program. If you terminate it while it is running a virtual disk could remain attached. Whoever owns that vhd/vhdx would not be able to attach it, and depending on your timeout settings for fslogix… it could take a very long time, and then give them a temporary profile.

  13. Yea, its strange. The vhdx detatches fine.
    I tested it again. Same thing. Trying to understand what it is that causing it. Redo the profile and its fast again.

  14. It’s a awesome tool. Just trying to figure out what it is (possible my environment)

  15. The tool don’t write any log to programfolder for me.

  16. Any chance the Size can be converted to GB instead of MB? It would be much easier to read.

  17. Will this tool also work on FSLogix O365 containers?

  18. Hi David,

    Would it be possible to provide the powershell source code behind the exe?
    If not, would it be possible to add search/sort functionality to the list?

    Great tool, Thanks!

  19. Hi David,

    It seems that this tool is not compatible with (a) DFS (share) and replication. This is to be expected as you point the tool to a DFS share that is in the background pointing to multiple (file) servers and it has no way to decide which containers are in use on which server. It’s a more complicated scenario currently not addressed with this tool. Apart from that, terrific tool!!

    • I use DFS as well, but we only use one path unless we are in a DR scenario. That said DFS should replicate changes, but it would not know if the disk was in use on one path vs the others.

  20. Hi David,

    We’ve been using the tool on a schedule for a couple of months now and it’s working great! However, there are a couple of vhds which are not shrinking when we are certain that they should. It looks as though there are a couple of problems within the disk (one example had errors in the master file table bitmap, for example. This issue would be solved by a chkdsk /f within you rtool, would it be possible for you to update to include this? Or perhaps to release the powershell code of the tool so I could edit myself?

    Thanks again for the great tool.

    • I have an update for the tool (will update the post shortly). I noticed that sometimes the disks do not shrink, and that adding a second defrag process fixes it.

  21. David,
    I’ve been using the tool for a few weeks now, and I noticed a problem. We use a differential disk to store changes to the profile during the sessions, which then gets migrated once the use logs off. This way, the profile.vhdx remains unlocked and the RW.vhdx is locked during the session.
    When we run your tool at night and there are still some users active, they skip the RW.vhdx cause it’s locked, but it does compact the userprofile.vhdx file. Afterwards, we notice that changes are not being saved in the profile anymore and according to the logs, the RW.vhdx cannot be merged, because the chain is broken. I suspect, by changing the master VHDX while there’s a differencing disk attached to it, breaks the chain. Are you aware of this?


  22. Great Tool. I am only missing some information on the vhdx file in th eGUI. That is the size of the virtual disk. If you mount it you see it in diskpart.
    Eg I have a VHDX which is size to 29 GB

    DISKPART> list disk

    Disk ### Status Size Free Dyn Gpt
    ——– ————- ——- ——- — —
    Disk 3 Online 29 GB 0 B *
    DISKPART> list partition

    Partition ### Type Size Offset
    ————- —————- ——- ——-
    Partition 1 Primary 29 GB 1024 KB

    That size does not change during compacting, but it would be nice to show it in the GUI.

  23. Ditto post #22 you need to add an accounting for a RW.vhd(x) file if differencing is used in the environment or you can corrupt the disk pair.

  24. Hi David,

    Great tool, thanks for posting.

    Is there any update to resolve the issue with the RW file?

    Many Thanks

  25. Hi David,

    I just noticed there’s a new version since I found this tool the first time. Do you have any changelog information somewhere?

  26. Hi David, great tool, and one I’ve promoted in the community… Bit of an issue though when working through a share I’m seeing 100% of the containers show Unlocked when enumerating, then when I start the Compact process, around 20% show Locked – True… – There are no Live sessions, and even looking on the fileshare, there are no open handles on any of these files. – Any idea?

  27. Is it already possible to run the exe silent with parameters so we can schedule it? If not will it be on your roadmap?


  28. Hi.

    Nice tool, may i ask for command line so i can schedule this todo compact?

  29. Hi David, first of all awesome tool!
    Since the update (2nd defrag pass), the discs is no longer shrink when i do it automatically via the CLI and task scheduler, while it works fine via the GUI. Did something change with the CLI functionality or am I doing something wrong here?

    • Thanks for this awesome tool! We are having the same issue as Kevin described. Via the CLI/Task Scheduler the VHDX does not shrink. Via the GUI it does. The CSV log shows 0 DiffMB for almost all VHDX’s.

 Leave a Reply

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



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