How to delete empty user profiles in a Terminal Server (Citrix) Environment

Author: NetworkAdminKB.com
Created: 2008-09-19
Modified: 2008-11-20

Issue:

After enabling "Delete cached copies of roaming profiles" in a GPO on you discover that user profile directories are being repeatedly created as users log in and out over time.

 

 

Cause:

This issue can be caused when programs or services running on the TS server do not allow for the proper deletion of the user profile on logoff. 

 

Solution:

Method 1

Determine what program or service is not properly releasing files or folders in the user profile path for deletion as the user logs off, then correct the issue.

 

Method 2

Another way to resolve this issue will be to run a script that detects and deletes these empty user profiles.  The scheduling of the script can be from every few minutes to once a day or week, etc depending on your environment.

 

Here is an example script.

 

@Echo Off

REM   Author: NetworkAdminKB.com

REM  Created: Sept. 19th, 2008

REM Modified: Sept. 19th, 2008

REM  Purpose: Universal batch file to delete the Empty local

REM             profiles from Terminal / Citrix servers.

REM           Run locally on the Terminal / Citrix Server.

REM

 

SetLocal

Set LocalProfiles=%SystemDrive%\"Documents and Settings"

 

For /D %%i in (%LocalProfiles%\*.*) Do Call :Loop1 "%%i"

Goto End

 

:Loop1

REM Echo %1

If Not Exist %1\NTUser.dat (

Echo Deleting: %1

rd /s /q %1

)

Goto :EOF

 

:End

EndLocal

Article ID: 103, Created On: 9/17/2011, Modified: 9/17/2011