Solved

Need to write a script to delete profiles

Posted on 2008-10-23
7
2,321 Views
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?
0
Comment
Question by:citrix009
7 Comments
 
LVL 18

Accepted Solution

by:
sk_raja_raja earned 100 total points
Comment Utility
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
 
LVL 18

Expert Comment

by:sk_raja_raja
Comment Utility
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
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 300 total points
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 300 total points
Comment Utility
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
 

Author Comment

by:citrix009
Comment Utility
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
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 300 total points
Comment Utility
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
 
LVL 11

Assisted Solution

by:KrAzY
KrAzY earned 100 total points
Comment Utility
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

#Citrix #XenApp #Citrix Scout #Citrix Insight Services #Microsoft VMMAP #Microsoft ADEXPLORE #Microsoft RAMMAP #Microsoft TCPVIEW #Microsoft AUTORUNS #Microsoft PROCESS EXPLORER #Microsoft PROCESS MONITOR
Several part series to implement Internet Explorer 11 Enterprise Mode
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.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now