FSLogix / Invoke-FslShrinkDisk

This script will shrink a FSLogix Disk to its minimum possible size
MIT License
155 stars 55 forks source link

Removing VHDX content marked as Excluded in the FSL Redirections.xml #51

Closed insufficient-funds closed 2 years ago

insufficient-funds commented 2 years ago

Hello - I'm not very fluent in the proper use of github, sorry if I do anything wrong here.

We've been using a new VDI environment using FSLogix for a couple months now. We've identified a number of file paths being saved to the user's Profile.vhdx that we decided to add to the Exclude list in the Redirections.xml.

Since content already within the VHDX doesn't get removed when you modify the exclusions, I wanted a way to handle removing the items via PS. I know there are some scripts at https://github.com/aaronparker/FSLogix/tree/main/Profile-Cleanup but we didn't want to add the Hyper-V stuff to get those PS commands.

Upon thinking on it, I decided to dig through the Invoke-FslShrinkDisk.ps1 and modify it slightly to add in a feature to remove vhdx content that is marked as excluded by the Redirections.xml file.

Invoke-FslShrinkDisk.ps1.txt

I've attempted to add my version of the script as text file to this post (link above).
What I did was add a parameter to the script "RedirectionsPath" allowing a user to pass the filepath to their redirections.xml file; added a function "delete-exclusions", and added a few calls to it. I tested it against a few vhdx files and our redirections file and it seemed to work great. The Delete-Exclusions function gets called just after a VHDX is mounted, before any of the size reduction stuff begins.

If you don't want to incorporate this into the official version of the script, that's fine by me. Just thought I'd share what I've done.

Changes by line: 73/74 - Parameter RedirectionsPath to script info 173-176 - parameter definition for RedirectionsPath 1086-1089 - param definition in the Optimize-OneDisk function 1162-1170 - logic to determine if the delete operation should be called; function call of Delete-Exclusions 1466-1498 - delete-exclusions function 1847-1859 - param definition in the optimize-onedisk function 1921-1929 - logic to determine if the delete operation should be called; function call of Delete-Exclusions 2234 - added redirectionspath to the ParamOptimizeOneDisk param 2251 - added redirectionspath to the ParamOptimizeOneDisk param

I wasn't certain if the Delete-Exclusions function would need to be re-defined inside the ScriptBlockForEachObject area the way the others are; I don't have a system with PS v7 to test it through; I assumed it would need to go there but I didn't add it.

insufficient-funds commented 2 years ago

For sake of sharing - I found a bunch of stuff was hitting the windows 260 char max file path limit; so updated the stuff I wrote to handle it.

Only change is within the delete-exclusions foreach dir in exclusions loop Invoke-FslShrinkDisk.ps1.txt .

JimMoyle commented 2 years ago

Hi @insufficient-funds I've thought about adding this before as people would find it useful. However inappropriate exclusions in redirections.xml are the primary source of odd behaviour and errors in FSLogix implementations and many people apply them incorrectly breaking their environment.

I could see adding this to the script would generate a lot of 'I ran your script and it broke my environment' issues so I decided against it.

If I did include it I'd think that your method would be a good way to do it though. I'm happy to leave your comment so people can implement your changes themselves, but I'm sorry I don't think I'll include them in the script.

Also as you note Aaron has a very capable script for doing exactly what you need here, so didn't want to replicate his work.

Thanks for taking the time to amend the script and share what you've done.

Jim

insufficient-funds commented 2 years ago

Completely understand the reasoning to not include it. As I run it against my entire fslogix profile group, I keep finding little issues here and there. Trying to troubleshoot inside of the parallel sessions has been interesting! Hopefully we don't have to use it when I have thousands of profile files in the future (60 currently, from our pilot group).

Thanks for your feedback on it!

JimMoyle commented 2 years ago

You're welcome