Jul 292019

Update: Added cli functionality.

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. To run via CLI simply run from command prompt and add the path to the root profile folder. (ie: ShrinkFSL.exe \\servername\share\profiles)
    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

  18 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?

    • No, but I have seen where running it once made it a little bit bigger, and then running it again on the same container shrunk it down.

  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.

 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>