In this tutorial we will use a command called Delprof that will help you delete disconnected User Profiles from Windows Terminal Server.
If your terminal server is a public one you might want to delete the User profiles in order to save disk space.
But if you just delete the profile folders you might have an issue when the user logs back in and the server tries to recreate the profile.
In order to avoid this issue Microsoft has released a small app called Delprof allowing you to delete the profiles automatically or interactively.
First you need to download and install Windows Server 2003 Resource Kit Tools
DELPROF [/Q] [/I] [/P] [/R] [/C:\\<computername>] [/D:<days>]</days></computername>
/Q Quiet, no confirmation.
/I Ignore errors and continue deleting.
/P Prompts for confirmation before deleting each profile.
/R Delete roaming profile cache only
/C Remote computer name.
/D Number of days of inactivity.
Now you can create a script that runs with a Scheduled Task or at Statup/Shutdown:
C:\Program Files (x86)\Windows Resource Kits\Tools\delprof.exe /i /q