Need to write a script to delete profiles

I need to write a script to delete profiles from the citrix server every night to clear the disk space. Any ideas?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can (on the citrix server) right click 'my computer' go to properties. 'advanced' and then 'user profiles' ...settings...
you can now scroll through all the profiles saved on the local computer and delete them

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
1.You can learn about the different profiles at

Unless your farms published apps and desktops are not load balanced across multiple servers,  you do not want to use local profiles, because each time a user logs in they are going to have different settings. Imagine, a user saves an important spreadsheet to the desktop, and then next day its not there. They can call the helpdesk.

Depending on your sites needs, you would choose either roaming profiles which are centrally stored on some file server, roaming mandatory profiles, multiple profiiles, or hybrid.

Roaming profiles will suffice where you are simply publishing desktops, and you want to allow users to retain their settings. The problem with roaming profiles is that they get filled with crap, grow, become corrupted and create a lot of headaches.

Mandatory profiles are similar to roaming profiles. An administrator creates a mandatory profile by saving  the dat file as With mandatory profile each time a user logs out their changes are lost.

If you have an application silo type environment, you may want to use a combination of mandatory and roaming, or what is known multiple profiles. Each time a user logs in a new profile is created which retains their settings from their roaming profile as settings from a mandatory profile. This is achieved with logon scripts in ADM.

Finally, for very complex environments you have hybrid profiles with the use of vb scripting.

Other best practises for profiles in TS environments include the following:

1 Set the PS server to delete local profiles on logoff
2. In ADM create redirects for the following My Documents, Application Data, Desktop, Cookies, Favourites, Templates
3. Exclude these directories from uploading My documents, print neighbhourhod, application data
4. Set the location of the profile in Terminal Services tab.

2.Specifically for your questions 1) how to delete user profiles, and 2) how to ensure TS profile is used check thiese:

One batch script I use to do it...
@echo off
for /f "tokens=*" %%a in ('dir c:\docume~1 /b /ad') do call :process "%%a" 
goto :eof
Set Profile=%1
if /i [%Profile%]==["Administrator"] goto :eof
if /i [%Profile%]==["All Users"] goto :eof
if /i [%Profile%]==["Default user"] goto :eof
rmdir C:\USERS\%Profile% /s /q

Open in new window

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Or a vbscript version:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
'ProfilesToKeep is an array holding the profile folder names to bypass in the removal process
ProfilesToKeep = Array ("All Users", "Administrator", "Default User")
Set objFolders = objFSO.GetFolder("C:\Documents and Settings\") 'Connect to C:\Documents and Settings object
For Each Folder in objFolders.SubFolders  'Iterate all subfolders
  arrTest = Filter(ProfilesToKeep, Folder.Name)  'Compare the folder's name to the array of profiles to keep
  If uBound(arrTest) = -1 Then 'If value is -1, then there was not a match...remove
    wscript.echo "Deleting " & Folder
    'objFSO.DeleteFolder (Folder)
  End If

Open in new window

citrix009Author Commented:
Sir Bounty,

I usually go to profiles and delete them as raja suggested to save disk space but as it has to be done almost every day that is why writing the script. Thanks for the script. One question I have is if there are any users logged in at the time when the script will run I would like to log them off first and then run the script. Could you help adding this feature to the script. Thanks!
I'm not very familiar with citrix, but if it works in that regard to the way terminal server does, there should be a logoff command that can be issued against the session (although then you may risk corrupting/losing data if the user is forced off).
Beyond that - which script are you using?
You could use the utility "delprof.exe" to complete this task.  I believe it is apart of the Resource Kit and a seperate download off  At the moment I don't have time to post a script, but you could write a simple batch file/vbscript to parse a text file of servers and run the command against.  Then you could set this as a scheduled task to run every X hours, X days, X weeks.  I'd suggest using delprof over deleting folders because delprof uses the same mechanism that is used when going through My Computer - Properties - Advanced.  It can tell if profiles are in use and not delete them (i.e. a logged on user) and profiles that shouldn't be deleted (i.e. Default User, All Users, Network Service, Local Service, etc.).

Now with that said, it will delete all profiles, so you need to make sure you don't or your users don't need anything in their profiles.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.