Script to clean up user profiles in a Citrix farm

You may have found yourself in a situation where you have had to rebuild a user’s profile to fix an issue or clean up old users’ local cached profiles from Citrix servers after they have left the organization. This wont pose a huge problem if  your Citrix farm is small. But if you have a large enough farm, going through this process of properly cleaning a user profile would be a very time consuming process.

The following steps are involved in properly cleaning up a user’s profile:

  1. Delete the registry key HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\<SID OF THE USER> on all servers.
  2. Take ownership of the user’s local profile folder on all Citrix servers (Eg: C:\Users\JohnDoe)
  3. Delete the local user profile folder on all Citrix servers.
  4. Take ownership of the user’s redirected folder (Eg: E:\USER_FOLDERS)
  5. Backup the user’s redirected folder.
  6. Take ownership of the user’s terminal server profile (Eg: E:\USER_PROFILES)
  7. Backup the user’s terminal server profile.

I’ve hated having to do this manually and so has my team, so I wrote this script that does all the steps mentioned above.

You can download the script here.

How to use the script:

  1. The script has to run on the server that hosts the user’s redirected folders and profile folders. You can experiment with this, but other configurations have not been tested as of writing this post.
  2. Place the script in a directory, edit it and modify the variables between the lines ********** Required Configuration BEGIN ********* and ********** Required Configuration END *********. There are examples provided within the script to help you configure the script.
  3. Run the script against a test user and ensure that the results are as expected.

Drop me a line if this post has helped you or if you have any questions about this script.


Leave a Reply

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