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
Update 4/21/2020: Fixed bug that didn’t assign drive letters to vhd(x) files when running via CLI. Which breaks the defrag, and in turn doesn’t free up any space for diskpart to shrink. Fixed version is 2004.1.
Update 4/23/2020: Added the ability to sort profiles in the GUI. Clicking the stop button should dismount vhd(x) files automatically. Uses optimize-volume instead of defrag – should be MUCH faster. Also does not need drive letters anymore. Version 2004.2
Update 4/27/2020: Tool now detects RW disks and will not attempt to compact multi session profile disks if in use. Version 2004.4
Update 4/29/2020: Tool will find hidden .vhd(x) files. Version 2004.5
Update 5/26/2020: Fixed the optimize-volumes to use “retrim” after defraging the volume. This will increase processing time, but shrink the vhd(x) files much more. Version 2005.1
I will investigate processing multiple vhd(x) simultaneously for a future release.

Do not use this tool if you are doing any differencing disks!
Diff disks, no problem!

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 diskpart to perform the shrink function.

Requirements:

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

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 5/26/2020)
https://david62277.sharefile.com/d-saad8432c8994f61b

  133 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
        diskpart
        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
        exit

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

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

    Regards,
    Michiel.

  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.

    • We also experience issues when a profile is in use. Only the RW.vhdx is locked but the tool tries compacting the non-locked profile disk. If profiles where a differencing disk is in use could be skipped it would be a great improvement.

      • I have not gotten around to messing with diff disks. Being that I don’t use them in my environment this may not get implemented.

  24. Hi David,

    Great tool, thanks for posting.

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

    Many Thanks
    Brian

  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?

    Thanks.

  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?

  30. Hey David,

    Just a FYI, this tool instantly gets blocked by Symantec Endpoint Protection the second you download it. I had to turn off my SEP, and then rename the file to get SEP to not instantly delete the .exe.

  31. Thanks for this great tool! One thing we noticed is that we run the tool from the command-line it runs fine but it doesn’t really compact the disk. We tried running with UNC path (ShrinkFSL.exe \\servername\share\profiles) and local path (ShrinkFSL.exe X:\UPDFolder) and both run fine, you can see the server is mouning and unmounting the UPD files.

    But it doesn’t compact the UPD files that much when we use the CLI. When we run the tool with the GUI it significantly decreases diskspace. Maybe this is a known issue?

    • Hi Rob.. we notice exactly the same. And scipting this is what you need to do this unnatended at night if all citrix sessions are automatically ended so the vhdx are not locked any longer. Hopefully this can be fixed.

  32. Great tool. I just test it in our test enviroment. It works great. Thank you.

  33. Has anyone successfully used this with FSL profiles in a VMware VDI environment? After I ran SrinkFSL and started up a VMware Horizon desktop, it created a new profile.vhd vs using the compacted one.

    • If you are using diff disks this could have happened. Don’t use this tool if you are using differencing disks. It is only looking for vhd/vhdx files.

  34. first of all this tool is very nice.. worked perfect for fslogix container. I tried to use this for Citrix Profile Container as well, but this doesnt worked. Does anyone know what is the exact different why this is working for fslogix container but for Citrix Profile Container not?

  35. I have run the tool from the GUI against a number of profiles but it always says DiffMB 0.
    It only takes a second to run the tool where I would expect it to take longer.
    Is there any way to determine that the DiffMB 0 is the actual value or that there has gone something wrong (debug log or something) ?

  36. Using the tool version from a few weeks ago, I have run the tool from elevated command prompt and the log shows that it is reducing quite a lot of the VHDs by marginal amounts, i.e. from 20MB to 300MB.

    Using the latest tool from 31/03/20 I get DiffMB=0 for all profiles.

    Going back to the original, older tool version repeated runs of that tool using CLI do not show further reductions.

    Then I run the tool again using the GUI and it reduces the size further.

    Using a specific VHD;

    CLI First run with older tool: 30.33MB reduction
    CLI Subsequent runs: 0MB reduction
    GUI run: 3659.13MB reduction

    • If you run the tool across all of your profiles and they are already reduced, running it a second time will most likely result in a 0MB difference.

  37. Hi,
    same problem here.
    Works correctly using GUI.

    Thanks!
    Great tool

  38. You Sir are a hero !
    Thanks very much

  39. Brilliant Tool, works very well with the GUI. We have over 2000 FSLogix disks and if you could get the CLI working again that would be great as we could have a scheduled task to run this weekly.

    • I run it as a weekly scheduled task as well, and the last time it ran it reduced the profile store by 10GB (over 300ish profiles). The more you run it the less fat it is going to cut out. The first time I ran it I got a total reduction of about 90GB, then a couple times later it was about 30GB, and the last 2 times it has ran it has done 15 and 10GB.

      • Hi David,

        As a scheduled task it is not shrinking a lot. When we run it GUI based it is shrinking. Microsoft Teams is creating empty space in the FSlogix disks so it would be nice to get shrinking to work again as a scheduled task. It does not matter if we run in multiple times it is just not shrinking when we run it as a scheduled task. If you read the comments a lot of people having this issue right now with the latest version. Hope you have time to have a look at it.

  40. Brilliant tool, using it on 2000 FSLogix profiles we got the disk space down to 3tb of the original 6tb usage (almost 50% savings!). sadly it doesn’t work when using it in CLI mode, would be really appreciated to get the CLI working again!

  41. Regarding the above which works fine through the GUI, I have some questions relating to the use of this tool via the command line.

    Q.

    When using the option \\ShrinkFSL.exe \\servername\share, I get “directory not found.”
    When using the option \\ShrinkFSL.exe \\servername\share this works. Can anyone advise where I have gone wrong?

    Q.
    When using the CLI, how do I actually stop the process? When viewed through Task Manager, the ShrinkFSL.exe process is not visible. The only way I have been able to stop it is to restart the server itself. Again any advice would be great.

    • Do a taskkill /f /im:shrinkfsl.exe

    • If it is in fact running, and you can’t see it – you’re not an administrator.

      I don’t understand your first question – the paths you are giving appear to be the same.

      CLI options
      shrinkfsl.exe \\path\to\profile\share
      or
      shrinkfsl.exe \\path\to\profile\share,4096

      The second would only touch profiles equal or greater to 4GB.

  42. I would like to delete files out of the vhd x is there any option that you could implemenet to do that, for example i would like to delete all ost from the profile.

    • That is not what this tool is designed for. You could try using redirections.xml to redirect .ost files to the “local” profile directory that is wiped at logoff

  43. Hi! We also see a massive difference when running it GUI vs running command line like this:

    ShrinkFSL.exe \\Severname\Fileshare\

    Working perfect using GUI. Using command line (or scheduled task..) it only shrink a tiny bit on each run.

    Would be nice if this could be “fixed”.

    Anyway – thanks for a great tool!

    Regads
    Fredrik

  44. Hi. Same here, it’s a great tool but indeed when i run it using the command line it doesn’t schrink the o365 vhd’s at all.
    But never the less i’m not complaining.
    Best regards, Ino

  45. Well guys, I screwed up. I was sure the cli was working, but that was just because I had attached all of the vhdx files before so the computer knew which drive letter to assign. Updating now.

  46. Hello, great tool! It would be nice to add an option to export a report.

    thanks!

  47. Great tool! The 2004.1 update fixed the not shrinking bug when using the cli.
    I have a feature request. Would it be possible to feed the cli with a .csv that contains unc file paths to vhdx files?
    I’m asking because i would like to run a scheduled task on a few 2016 servers so I can split the load and shrink multiple vhdx containers simultaneously.

    • Hi, have spread the .VHDX files to a lot of different shares?
      If not – you do not need to point to the root of the users VHDX. Point to the share it self, and the tool will scan for .VHDX files in all the sub folders.

  48. Dear developer,

    Great tool you have here but it hasn’t turned out too good for our environment. I ran it once and ever since, users complain that applied settings are gone every time they log back in after logoff. Any idea why this is happening? Thank you in advance

  49. Hi! (I`m not the developer 🙂 ) Have you configured FSLogix to allow Multiple Connections? Do users get the RW.VHD(X) file in the profile folder when logged on? If you then did run this tool while users where logged on, the tool made change to parent disk and some issued occurred when the difference disk tried to write back (to the changed parent disk) when logging off. Just a theory.

  50. Firstly this looks like a great tool. Not sure but can you post all the switches available and what they do please?

    • This will attempt to compact every vhd(x) in a directory and all subdirectories
      shrinkfsl.exe \\root\profile\share

      This will attempt to compact every vhd(x) in a directory and all subdirectories that are equal or greater than 4GB in size
      shrinkfsl.exe \\root\profile\share,4096

  51. Noticed that it doesn’t cope well with apostrophes, for example a profile disk called Profile_o’sullivanr.VHDX appears to get stuck at the diskpart stage (diskpart process starts, stops, starts, stops etc.). Expect one or more references to the name of the VHDX in the script might need some quotes putting around it in order to cope with the special characters (or similar)? Thanks.

    • As long as it is a ‘ and not a ` it should work. Have you tried the latest release?

      • Apologies for delay. Yes, I noticed a newer version the day after I posted and that worked fine with the ‘ characters. Great utility, will keep checking back for future updates. Thanks.

  52. Hi,
    thank you very much for this useful tool. Also with the latest version 23/04/2020 there is different result between run the tool as scheduled task or using the gui interface. With the gui interface you free much more space. You can obtain better result if you mount the vhd, optimize it with windows defrag, dismount and lunch again shrinkfsl using the gui. So I want ask you if it’s possible in your script automatically mount file, defrag it, and after optimize it everything automatically. And my last question is why so different between scheduled and gui process ? Thank you in advance.

  53. Your work is amazing, thank you for sorting out the schedule task issue, I was just about to look it up. Keep up the great work.

  54. Thanks again for the nice work an a very useful tool!

    One question, could you make the program able to see folders with the “hidden” attribute?

    If i point directly to the hidden folder it works, but if it`s a hidden subfolder some where under the root path the program don´t “see” it.
    It`s the same with both GUI and CLI.

  55. This looks amazing! We have some old non fslogix upd’s that I’d like to use this on. No problems?

    • Not trying to be pushy or demanding, just offering suggestions; would incorporating Sidder.exe into the gui be feasible? Easy enough to do on its own but would be nice to find specific users. Thank you so much for this utillity.

      • FSLogix profiles are under a folder named _ by default (I reverse mine for easy sorting though). Also the .vhdx files are named Profile_.vhd(x). So, I don’t see the need for sidder.exe.

  56. I just downloaded the tool this morning and it is not working. Immediately returns 0. Went back to the old version and that is working correctly.

    • What do you mean it returns 0? Make sure you are pointing it to the root of the profile share.

      • Yes I am using the old version fine. With the new version I select the vhdx and it immediately returns the results 0 diffMB on all VHDX files. I change back to the older version and it works fine.

  57. New version doesn’t compress from GUI or command line for me. Tried the old version (dated 10/10/2019) and it worked. Why would new version not work but old does?

  58. Thanks for this tool it’s great. I’ve been testing this and it seems that it does not do a defrag? I’ve been running this on all my VHDX file and it seems to do a good job but I noticed I had a 7GB VHDX file but when I cracked it open it only had 1GB of actual data. Since it was mounted I ran a defrag on it and discovered it was 14% fragmented. After I ran a defrag I was able to leverage your program to shrink it to 1GB.

    Can you add Defrag to the process?

    • I noticed I had an older version but it still seems to have the same problem. Optimize-VHD power shell command does not do a true defrag.

  59. Hi again! Some questions and feedback.

    1. The later versions of this program uses optimize-volume instead of defrag.
    Would it be any with benefits of combining these methods? More optimized disks?
    E.g. first run defrag (with older version), then run again optimize-volume (latest version)

    2. “Does not need drive letters anymore” (From Version 2004.2)
    In my experience, all versions still assign the disk a drive letter.

    3. Latest version does not seem to create log file when running in GUI mode. Work in CLI mode.

    Thanks again!

    Regards
    Fredrik

  60. It seems like the different approaches has very different results on different disks.
    Guess it depends on how the data and white spaces on the disks are.. (?)

    Here is an example where the new version not did free up any space at all, but the old version did shrink A LOT.

    New version (2004.5.0.0)

    “Profile”,”SizeBeforeMB”,”SizeAfterMB”,”DiffMB”,”Locked”
    “TSProfile.V6.VHDX”,”4772″,”4772″,”0″,”False”

    Older version (2004.1.0.0)

    “Profile”,”SizeBeforeMB”,”SizeAfterMB”,”DiffMB”,”Locked”
    “TSProfile.V6.VHDX”,”4772″,”964″,”3808″,”False”

    I have also done testing, where the result was totally different. The new version did free up a lot of space on the same disk as the old version not did free up anything.

    • What about maybe two passes, defrag first, then compact? Maybe even as an option

      • Yes, that is what we currently are doing. First 2004.1.0.0 and then 2004.5.0.0
        The second run does not seem to do much – when it comes to freeing up space.

  61. Hi David,

    This tool works great but in order to get approval to use it in my company I will have to show Source code.

    Is that something you might be able to make available?

    Thanks

    Paul

  62. Hi David,

    Thanks for this great tool. However, its not compating our profile disks, it seems that the disk optimization does not free up any empty space like defragmentation would. I came across another powershell script that does this exactly and as a test, it frees up 5GB from a 6GB profile. This same profile disk, passed through your tool only frees up 300 MB leaving more than 5 GB profile behind.

    I would rather use your tool and have my hopes that you are able to resolve this.

    Regards,
    Richard – Exite ICT

  63. New version (2004.5.0.0) isn’t working for me, doesn’t compress some of the VHD’s. Some do, but the results from a really old version are far better. Does anyone have a link to version 2004.1? I don’t have it anymore. Thanks.

    • Seconded, this would be really useful if someone has older versions as I’m seeing almost no gains on the latest version

  64. Hello David,

    is it also possible to still share version 2004.1 (with defrag instead of optimize-volume) of the tool? It seems that the gains with defrag are significant more than with using optimize-volume.

    thanks in advance,

    Joeri

    • +1

      Love the concept of this tool. But I have users with 6GB .VHD files, and the profiles are only 1 -2 GB in size. Running the latest ShrinkFSL tool, I only get marginal gains 20 – 200MB.

      As per the above posters request, I’d like to get a copy of the older version (or an updated version) that uses defrag instead of optimize-volume.

      Thanks in advance,
      Dan

  65. I believe the latest version is not working properly, I almost see no shrink, and the script is finished In like 5 minutes with more then 100 profiles?

    • The latest script shrinkt 9024MB on 157 profiles.

      Script version 2003.1.0.0 (yes we still use one of the first scripts) shrinkt 569984MB on 157 profiles..

  66. Hi, sorry, but version 2005.1 still isn’t reducing VHD’s much. I ran it against a 5GB VHD, and it took off 80mb. Then I ran the old one (Version 1.0.2.0) against the same VHD and it took off 3542mb.

    • I just compacted a vhdx with the newest version, restored it, and compacted again with the last version that used defrag.exe – they reduced the profile the same.

      • Let me give you a bit more spec.

        VHD (we use VHD, not VHDX) storage server is Windows Server 2019 Version 1809. VHD are created by FSLogix 2.9.7237.48865 from Citrix Servers running Citrix Virtual Apps and Desktop 7 2003.

        I made a copy of a VHD that I know is oversized from one of our users:

        Version 2005.1 Results from Copy 1:

        First Run: Initial 7047.77, After 7047.77, Diff 0
        Second Run: Initial 7047.77, After 7047.77, Diff 0

        Very fast runs on the above, under 20 seconds.

        Version 1.0.2.0 Result from Copy 2:

        First Run: Initial 7047.77, After 3905.65, Diff 3142.12
        Second Run: Initial 3905.65, After 3901.64, Diff 4.01

        Slower runs on the above, about 60 seconds before results.

        I think this is a great tool so please do keep up the good work.

 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>

(required)

(required)

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