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?
citrix009Asked:
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.

sk_raja_rajaCommented:
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
0

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
sk_raja_rajaCommented:
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

3.http://ts.veranoest.net/ts_profiles.htm
http://www.brianmadden.com/Forum/Topic/95680
0
sirbountyCommented:
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
 
:process
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

0
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.

sirbountyCommented:
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
'UNCOMMENT THE NEXT LINE IF THE Folder IS CORRECT
    'objFSO.DeleteFolder (Folder)
  End If
Next

Open in new window

0
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!
0
sirbountyCommented:
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?
0
KrAzYCommented:
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.
0
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
Citrix

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.