Need to write a script to delete profiles

Posted on 2008-10-23
Medium Priority
Last Modified: 2012-05-05
I need to write a script to delete profiles from the citrix server every night to clear the disk space. Any ideas?
Question by:citrix009
LVL 18

Accepted Solution

sk_raja_raja earned 300 total points
ID: 22791261
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
LVL 18

Expert Comment

ID: 22791287
1.You can learn about the different profiles at http://support.citrix.com/article/CTX110351

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 user.man. 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:
1)  http://support.microsoft.com/?kbid=274152
2)  http://support.microsoft.com/?kbid=246132
3) http://ts.veranoest.net/ts_profiles.htm

LVL 67

Assisted Solution

sirbounty earned 900 total points
ID: 22791408
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

LVL 67

Assisted Solution

sirbounty earned 900 total points
ID: 22791420
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


Author Comment

ID: 22792724
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!
LVL 67

Assisted Solution

sirbounty earned 900 total points
ID: 22792775
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?
LVL 11

Assisted Solution

KrAzY earned 300 total points
ID: 22793658
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 www.microsoft.com/downloads.  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.

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
#Citrix #Citrix Policies #XenDesktop #VDI #POC #Citrix Univeral Printer Driver #Citrix UPD
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question