Update: Script is updated with new features and moved to github.

When you have a share with FSLogix containers you probably want to keep this in sync with you active directory. Users who are deleted, inactive or disabled can still claim space on the file server. This script will read all container folders and match them against the active directory useraccounts and delete the containers if needed.

All information is in the script.  Have fun with it and leave a comment when using or when having issues.

Here is the script: https://github.com/JeroenTielen/PowerShell/tree/main/FSLogix_Cleanup_Containers

Keep in mind, I’m not a scripter/devver 😉 So the script can be shorter/smarter but this works either. I’m not responsable for any damage or deleted containers 😉 Usage of the script is your own responsability.


Jeroen Tielen

Experienced Consultant/Architect with a demonstrated history of working in the information technology and services industry. Skilled in Citrix, Microsoft, VMware, Ivanti, etc.

6 Comments

Joep · August 10, 2022 at 15:46

Hi Jeroen,

Thank you for this script. We are not using FSLogix Flip Flop, but I can’t figure out what to change about the script to make it work. Could you help me with this?

Kind regards,
Joep

    Jeroen Tielen · August 10, 2022 at 15:54

    Ahh you are the one in a thousand which is not using flip flop 😉 You need to change the script so it reads the username from the last part of the foldername. I never ever use that kind of naming convention as it is not easy to find the user his profile.

Tom Schoen · November 2, 2022 at 15:29

Thanks for the inspiration! Did not exactly use yours but served as a great basis to develop my own. Should it help you, you can find it here! I built a flipflop switch into it as well.

https://github.com/tompatta/PowerShell/tree/main/FSLogix%20Cleanup

    Jeroen Tielen · November 9, 2022 at 13:47

    Ahh lovely Tom. That is community power. Thanks for sharing.

Andrew · January 13, 2023 at 00:08

This script looks amazing and exactly what I have been trying to build myself. When I try and run it in my environment I am getting the following error:

Exception calling “Substring” with “2” argument(s): “Length cannot be less than zero.
Parameter name: length”
At line:58 char:5
+ $UserName = $pathItem.Name.Substring(0, $PathItem.Name.IndexOf(‘_ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException

Get-ADUser : Cannot validate argument on parameter ‘Identity’. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:60 char:45
+ $Information = Get-ADUser -Identity $UserName -Properties sAM …
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Automatically clean up FSLogix Profile Containers – The Cloud Admin · November 9, 2022 at 19:24

[…] Jeroen Tielen created a cool script that does some of the things I wanted it to do, but not all of it. […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

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

%d bloggers like this: