Jump to content
Welcome to our new Citrix community!
  • How to Prune a FSLogix Profile


    cugcblogs

    raydavis22rnd-1.jpgby Ray Davis, CTA

    Last year, I put out a blog on FSLogix's quick Default Exclusions explanation (see FSLogix Default Exclusions Explanation and Quick Fix (mycugc.org).

    That solution is working very well. But anything that remains in the FSLogix Profile before I reversed the GPO to purge the %Temp% and INetcache doesn't purge from the user's profile. I needed a quick solution to achieve this, and I recall reading about this somewhere, but I couldn't remember where. Later that night, I went to bed with it heavy on my mind, and while I was sleeping, around 3 am or so, I rose out of bed remembering reading Aaron Parker's FSLogix blogs a couple of years ago. At this time, I hopped on the computer and did a quick google search: "How to purge Fslogix Profiles." Sure enough, the name "Steal Puppy" stuck out. Most often, it's the usual way of life for me. I am always thinking of what I don't know, how I can do whatever I am dealing with, and even how to get to the next level. Sadly, it consumes me mentally, yet I always find a solution from other talented people in the industry. Ok, let's get back on track. Here is the article I was referencing:

    A Practical Guide to FSLogix Containers Capacity Planning and Maintenance (stealthpuppy.com)

    Please understand that I copied the pruned material and put it here to help you understand what I am talking about in my references. 

    Prune the Profile

    Not all profile locations are candidates for adding to the redirections.xml and excluding from the Profile Container. Consider history and cookie folders that would negatively impact user experience if they were not maintained across sessions. In this case, we can run regular maintenance on additional folder locations inside the profile to keep the size in check. This approach won't directly reduce the size of the profile per se, but will assist in containing growth.

    I've written a PowerShell script - Remove-ProfileData.ps1, that can prune or delete a set of target files and folders. The script reads an XML file that defines a list of files and folders to remove from the profile."

    "Actions on a target path can be:

    • "Prune - the XML can include a number that defines the age in days for last write that the file must be older than to be deleted"
    • "Delete - the target directory will be deleted. The Delete action will delete the entire folder and sub-folders"
    • "Trim - where the target path contains sub-folders, this action will remove all sub-folders except for the most recent. This approach is implemented to clean up applications such as GoToMeeting that can store multiple versions in the profile"

    The script supports -WhatIf and -Verbose output and returns a list of files removed from the profile. Add -Verbose will output the total size of files removed from the user profile and processing time at the end of the script. All targets (files / folders) that are deleted, will be logged to a file. Deleting files from the profile can result in data loss, so testing is advised and the use of -Confirm:$false is required for the script perform a delete. To prune the profile, run the script as a logoff action.

    A word of caution - this script is unsupported. If you would like to help improve the script, pull requests are welcome.

    In my testing, I needed to prune a section of the profile. I have an application that uses IE (soon Chrome Edge), but I need to get all this trash out for now. It seems IE is cache-heavy for the web-based application. But the IE cache isn't just for IE. Other trash goes into here, and if I prune it, the area is empty.

    As you can see below,  the INetcache folder is dumping it to the local_username. But it's not getting the old stuff because the GPO was updated and put in after I realized it wasn't working in my previous blog. Anything before the GPO was updated does not purge the data.

    As you can see here in my example, the username_local is moving it to the scratch area. But notice the date on the folders. It's moving new stuff only!

    \\VDI\c$\Users\local_Test01\INetCache

    davis020422-01.png.48d0b2505353ac1264e6ba0bea339089.png

    Perhaps this may still be a factor for the IE app because it shares the INetcache. But look at the actual location of what isn't redirected. You can see that the old stuff is still lingering around. This means that IE is looking at the INetCache for the overall "Cache storage." Some Web applications like the one I have in this environment, once the overall Cache Storage location is used up. Well, the application becomes extremely slow.

    \\VDI\c$\Users\Test01\AppData\Local\Microsoft\Windows\INetCache

    davis020422-02.png.e505ae4b77a40d178439d51c781ae1db.png

    To ensure this location is purged, we can schedule the "Remote-Profile.ps1 script to run and take care of this. The script needs a Target file. The Target file is called with the parameters to understand what needs to remove from the FSLogix profile.

    A reminder of how it works

    "A PowerShell script - Remove-ProfileData.ps1, that can prune or delete a set of target files and folders. The script reads an XML file that defines a list of files and folders to remove from the profile."

    davis020422-03.png.e3e516bad398a5518dad15ff065baef1.png

    Before

    The screenshot shows the old data.

     

    davis020422-04.png.c71a2e55c3a15e365b09b2174477b3df.png

    After

    I remoted to a VDI machine, and then I executed the script.

    C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -File "\\Domain\NETLOGON\CitrixScripts\WemExternalTask\ProfilePrune\Remove-ProfileData2.ps1" -Targets "\\Domain\NETLOGON\CitrixScripts\WemExternalTask\ProfilePrune\targets.xml" -LogPath \\Domain\NETLOGON\CitrixScripts\WemExternalTask\ProfilePrune\logs -verbose

    Location of InetCache throug UNC

    \\VDI69\c$\Users\Test01\AppData\Local\Microsoft\Windows\INetCache

    It looks like this has done the job for me, and there are many ways to implement this. I don't advise you to do it at logon, though, as it would impact the logon performance. You can do a Logoff script, scheduled task, or use a UEM tool.

    davis020422-05.png.cc2a470db33344599391a2268d994039.png

    I am a big WEM fan myself. I don't use anything else at the moment. That alone is a whole other topic 😊

    Open the WEM Admin Console>External Task

    davis020422-06.png.c1f267320407fca5838d431d8366c545.png

    Click Add at the bottom, and fill in the data to the script location.

    It is calling PowerShell then the argument is to the location where the meat and potatoes reside.

    Argument

    -Executionpolicy bypass -File "\\ sillyrabbit.org\\NETLOGON\CitrixScripts\WemExternalTask\ProfilePrune\Remove-ProfileData2.ps1" -Targets "\\sillyrabbit.org\NETLOGON\CitrixScripts\WemExternalTask\ProfilePrune\targets.xml" -LogPath \\ sillyrabbit.org\\NETLOGON\CitrixScripts\WemExternalTask\ProfilePrune\logs -verbose

    davis020422-07.png.b1c7de632af6329d2a4d08503a4b0491.png

    Now, Click Assignments>add to the desired assignment.

    davis020422-08.png.050a566380a566888214345ae761628c.png

    Select what Filter you have. I keep it elementary most times and do "Always True."

    davis020422-09.png.0c782d1114b4f505b44759b29b5ef827.png

    Now it's ready to go. Of course, you can refresh the WEM agent and force it.

     


    User Feedback

    Recommended Comments

    Added the script via logoff batch file.

    Modified targets file to check only Teams and Office files.

    Changed the log file name. (Added username)

    Takes between 300 ms local profile to 6 sec 0365 FSlogic profile to process if there is nothing to delete.

    I’ll test it further to see if there are any unexpected issues with UPM /FSlogix when you have this in the mix.

    So far looks like working solution.

     

    @echo off

    set ScriptDirectory=%~dp0

    powershell.exe -ExecutionPolicy Bypass -Command "& '%ScriptDirectory%Remove-ProfileData.ps1' -Targets '%ScriptDirectory%targets.xml' -LogPath '\\afsprofiles\office$\_Remove-Profiledata' -Confirm:$False -Verbose"

    First real user cleanup results.

    [21/02/2023 14:45:50]: Total file size deleted 1300.66 MiB.

    [21/02/2023 14:45:50]: Time to complete 56923.4432 ms.

    Link to comment
    Share on other sites

    Hey Ray,

     

    I would like to delete all files older then 10 day in the download folder of the user. In our case, the download folder is redirected to the home folder. When I introduce %userprofile%\Downloads in Windows Explorer, I am in my Download directory.

     

    But when I run the scritp with prune and 10 days, no files or all files are deleted. I tried following targets:

     

    No files are deleted:

    %userprofile%\Downloads

     

    No files are deleted:

    C:\Users\%username%\Downloads

     

    All files are deleted, also files newer than 10 days:

    H:\Downloads\*

     

    Any idea why this i not working with the download folder?

     

    Thanks and Regards,

    Roberto

    Link to comment
    Share on other sites

    I am sorry, I do not know why it's not working in your environment. Are you on World of EUC?

    If you remove the 10 day part, will it delete anything by chance? Add the Verbos and what if to see what it's trying to do.

    Link to comment
    Share on other sites



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...