MrPstv Posted May 6, 2010 Posted May 6, 2010 Hello , I need a script to delete users temp files i.e. cookies from the profiles on the workstations and server as we use roaming profiles or another solution for this ? checked a users profile on a workstation and 7000+ cookies. need to reduce log on and log off times. Any pointers please.
mac_shinobi Posted May 6, 2010 Posted May 6, 2010 what paths are you reffering to that you want to delete the items from ?
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 There's a setting in Active Directory to prevent temporary internet files beings copied across the network. If you can't find it, I'll dig out the settings. If you could that would be great.
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 (edited) what paths are you reffering to that you want to delete the items from ? The paths are from the workstation C:\Documents and Settings\dadams\ Server path \\curricsvr1\Profiles$\dadams\cookies Edited May 6, 2010 by MrPstv
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 In AD, under User Configuration>Administrative Templates>System>User Profiles there's a section to exclude any folders you want in a roaming profile. In the help, it says that - by default - History, Temp Internet files, etc are excluded from the roaming profiles. Are you sure everything's OK with your setup? P.S. There's also a setting to limit the profile size. Thanks for the info i will have a looky at group policy, but i still need a script to delete this unwanted temp files.
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 would this work for the workstations ? c: cd\ cd C:\Documents and Settings\%username%\Local Settings\Temporary Internet Files del *.* /f/s/q cd \ cd c:\Documents and Settings\%username%\Local Settings\Temp del *.* /f/s/q exit
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 You should be able to get away with del /s /f /q "%userprofile%\Local Settings\Temporary Internet Files" <<<- don't forget the quotes del /s /f /q %temp% del /s /f /q %tmp% %userprofile% is better than C:\Documents and Settings\%username% as it guarantees to hit the profile. As does the %temp% variables. I've included the lesser-used %tmp% just for the hell of it. Just tried it thanks , .It needs to be tweaked a tad to allow deletion of all users cookies from me running the script as adminstrator not just my own cookies.
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 can anyone shed a bit more light on this script please.
JAB1a Posted May 6, 2010 Posted May 6, 2010 Hello, I have the same problems, user profiles are getting full up with pf*.tmp files (something to do with office) and thousands of cookies which are making profiles huge compared to normal (Size:83Mb, Size on disk:139Mb), I have the GPO setting that excludes some folders from roaming profiles but the ones it says are excluded by default are definutly not exculed, every other part of the GPO is working and this happens on 3 different sites that I work at. I have set up a test user and a fresh GPO and still the temp files and internet files are sent back to the server. Could your script be added to the log-off script in a GPO of each user or OU to delete the files before syncing back to the server or is the log-off script (applied by the GPO) loaded after the profile has been sent back to the server? Our pupil logons take about 1minute with a fresh profile but after a week its taking about 5-10minutes to logon. I know compared to some systems this is still fast but I have redirected the desktops, my documents, application data (all with offline access disabled) so the only files that are taking ages are the tmp files etc i guess. Another idea is, would changing all the profiles to manditory stop the temp files being written back to the server? Thank you for any help You should be able to get away with del /s /f /q "%userprofile%\Local Settings\Temporary Internet Files" <<<- don't forget the quotes del /s /f /q %temp% del /s /f /q %tmp% %userprofile% is better than C:\Documents and Settings\%username% as it guarantees to hit the profile. As does the %temp% variables. I've included the lesser-used %tmp% just for the hell of it.
MrPstv Posted May 6, 2010 Author Posted May 6, 2010 apologies for my lack of knowledge in scripting but do i add the above script to the previous script or use this as is? Thankyou for your help again.
srochford Posted May 6, 2010 Posted May 6, 2010 I think this is approaching it from the wrong end; you would be better to delete them from the server copy overnight. When a user logs on the next day they will copy down a clean profile. On the server I'm guessing you've got profiles in (say) d:\profiles with each user under that: d:\profiles\david d:\profiles\gordon d:\profiles\nick etc If this is the case then you want to create a batch file like this: d: cd \profiles for /d %%i in (*) do rd "%%i\cookies" /s /q What this does is change to the correct drive and folder. The for statement then looks for each directory (/d switch) and executes the stuff after "do" for each one, substituting its name for the %%i bit Schedule this to run overnight (or do it manually when you know most people are logged off) If you want to check what it's doing then add a pause command: for /d %%i in (*) do rd "%%i\cookies" /s /q & pause This will do the first rd command and then wait for you to press a key - you can then see if it did the right thing! (Make a dummy profile called 11111 or something which comes at the top of the alphabetical list for safety) If your folder structure is different from this (eg split by year) then you should be able to do something like this: d: cd \profiles\year7 for /d %%i in (*) do rd "%%i\cookies" /s /q cd \profiles\year8 for /d %%i in (*) do rd "%%i\cookies" /s /q cd \profiles\year9 for /d %%i in (*) do rd "%%i\cookies" /s /q - just adding extra pairs of lines for each year group. You can then schedule this to run every night. I'm sort of surprised that this is causing a problem - cookies are supposed to be very small files (typically well under 1kb) My own cookie folder is only 15kb in size so unless something is storing stuff in cookies which shouldn't be there then I don't know if this is the problem. I would look at the profiles for a couple of users with problems using (eg) Treesize - JAM Software - Windows Freeware This will show you which folders in the user's profile are taking up the space and slowing things down. Finally (!) you might want to look at redirecting cookies to the user's home drive - that way they don't get copied at logon/off so you don't have to worry about how long they take. Redirect Favorites and Cookies folder using a Group Policy has a good article on how to do this.
srochford Posted May 6, 2010 Posted May 6, 2010 I think this is approaching it from the wrong end; you would be better to delete them from the server copy overnight. When a user logs on the next day they will copy down a clean profile. On the server I'm guessing you've got profiles in (say) d:\profiles with each user under that: d:\profiles\david d:\profiles\gordon d:\profiles\nick etc If this is the case then you want to create a batch file like this: d: cd \profiles for /d %%i in (*) do rd "%%i\cookies" /s /q What this does is change to the correct drive and folder. The for statement then looks for each directory (/d switch) and executes the stuff after "do" for each one, substituting its name for the %%i bit Schedule this to run overnight (or do it manually when you know most people are logged off) If you want to check what it's doing then add a pause command: for /d %%i in (*) do rd "%%i\cookies" /s /q & pause This will do the first rd command and then wait for you to press a key - you can then see if it did the right thing! (Make a dummy profile called 11111 or something which comes at the top of the alphabetical list for safety) If your folder structure is different from this (eg split by year) then you should be able to do something like this: d: cd \profiles\year7 for /d %%i in (*) do rd "%%i\cookies" /s /q cd \profiles\year8 for /d %%i in (*) do rd "%%i\cookies" /s /q cd \profiles\year9 for /d %%i in (*) do rd "%%i\cookies" /s /q - just adding extra pairs of lines for each year group. You can then schedule this to run every night. I'm sort of surprised that this is causing a problem - cookies are supposed to be very small files (typically well under 1kb) My own cookie folder is only 15kb in size so unless something is storing stuff in cookies which shouldn't be there then I don't know if this is the problem. I would look at the profiles for a couple of users with problems using (eg) Treesize - JAM Software - Windows Freeware This will show you which folders in the user's profile are taking up the space and slowing things down. Finally (!) you might want to look at redirecting cookies to the user's home drive - that way they don't get copied at logon/off so you don't have to worry about how long they take. Redirect Favorites and Cookies folder using a Group Policy has a good article on how to do this. 2
JAB1a Posted May 10, 2010 Posted May 10, 2010 Thank you srochford, your batch file worked perfectly. I will trial adding a hidden folder to the users home directory which will have the cookies folder redirected to it and see how it goes, Im in the worst offending site on thursday so will let you know about the treesize figures of the profiles there. The cookie folder in profiles at this site is about 700Kb but size on disk was about 6.8Mb but all gone now
MrPstv Posted May 11, 2010 Author Posted May 11, 2010 Hello , Just to clarify something, We have students with individual logons example 03testa ,03haveago,03itdontwork,03pullmyhairout. We have this set up for 400 students and the staff are setup as example bbuilder, how would i apply this in the script? the drive letter is x , or \\curricsvr1\profiles$, sorry but i just cant get my head around scripts!!!
JAB1a Posted May 11, 2010 Posted May 11, 2010 Big thanks to SRochford with his script thats its now nice and simple.. To make the script just open Notepad and copy&paste the code into a new text document, then save as and change the file type to 'all files' and then remember to add the .bat to the file name (script.bat). If you are running this on the server then this is the code I think you should use (this is asuming that the partition you have the Profiles$ folder on is drive letter X: and that the profiles folder is at the root of the drive (X:\profiles) if its not then change the drive letter in the script to the one you need and add the parent folders name/s before the \profiles (cd studentfolder\profiles) X: cd \profiles for /d %%i in (*) do rd "%%i\cookies" /s /q & pause If you are running this from a workstation logged in with admin rights on the server then you can just map a drive letter to the folder or use this script NET USE X: \\curricsvr1\profiles$ X: for /d %%i in (*) do rd "%%i\cookies" /s /q & pause as SRochford says you should make a temp profile folder with the name 0000 inside your profile folder so it definutly comes first and then add a cookies folder inside it. both the scripts have the added pause so you can use it just on your temp profile folder and cancel if something is not right. I hope this helps, and if it works then please just us know
kili Posted June 9, 2010 Posted June 9, 2010 I think this is approaching it from the wrong end; you would be better to delete them from the server copy overnight. When a user logs on the next day they will copy down a clean profile. On the server I'm guessing you've got profiles in (say) d:\profiles with each user under that: d:\profiles\david d:\profiles\gordon d:\profiles\nick etc If this is the case then you want to create a batch file like this: d: cd \profiles for /d %%i in (*) do rd "%%i\cookies" /s /q What this does is change to the correct drive and folder. The for statement then looks for each directory (/d switch) and executes the stuff after "do" for each one, substituting its name for the %%i bit Schedule this to run overnight (or do it manually when you know most people are logged off) If you want to check what it's doing then add a pause command: for /d %%i in (*) do rd "%%i\cookies" /s /q & pause This will do the first rd command and then wait for you to press a key - you can then see if it did the right thing! (Make a dummy profile called 11111 or something which comes at the top of the alphabetical list for safety) If your folder structure is different from this (eg split by year) then you should be able to do something like this: d: cd \profiles\year7 for /d %%i in (*) do rd "%%i\cookies" /s /q cd \profiles\year8 for /d %%i in (*) do rd "%%i\cookies" /s /q cd \profiles\year9 for /d %%i in (*) do rd "%%i\cookies" /s /q - just adding extra pairs of lines for each year group. You can then schedule this to run every night. I'm sort of surprised that this is causing a problem - cookies are supposed to be very small files (typically well under 1kb) My own cookie folder is only 15kb in size so unless something is storing stuff in cookies which shouldn't be there then I don't know if this is the problem. I would look at the profiles for a couple of users with problems using (eg) Treesize - JAM Software - Windows Freeware This will show you which folders in the user's profile are taking up the space and slowing things down. Finally (!) you might want to look at redirecting cookies to the user's home drive - that way they don't get copied at logon/off so you don't have to worry about how long they take. Redirect Favorites and Cookies folder using a Group Policy has a good article on how to do this. Well done srochford .This is the way I do it directly on the server but I don't bother with cookies as these are dealt with by GPO not copying back IE temp files etc.. I do delete the following though *.exe *.cmd *.bat *.wmv and a whole host of other extensions I have one script with a list of students folders which checks every 15 minutes to deal with repeat offenders who copy exe's and mp3's to their home folder. Just one thing I would add to the script and thats the following cd /d d: ( or whatever drive the script started from) This one from experience when Microsoft made changes to the cmd program and a windows server update had my script on completing the sweep of students folders happily jumped from the d: drive to c:\windows\system and started to delete all the exe's. So make sure you return the script to the relevant drive with cd /d d: ( or whatever your drive letter is) and put in an exit command to close the session exit ( and the exit cmd to close the cmd session) Kili
JAB1a Posted June 14, 2010 Posted June 14, 2010 Hi Kili, Thanks for your post, could you possible post your script on here so I could take a look at the syntax Thank for your time:o
kili Posted June 14, 2010 Posted June 14, 2010 (edited) Hi Kili, Thanks for your post, could you possible post your script on here so I could take a look at the syntax Thank for your time:o This is the script I use for deleting from Teachers Home folders and profiles. Place the script on the drive you want to run it from in my case it's drive D REM -------- If you make changes to this file please leave your name and date of editing --- REM ------ Change focus to drive D: data\home folders\teaching staff -------- REM cd /d d:\"Data\home folders\teaching staff" del *.flv *.avi *.qt *.msi *.zip *.tmp *.exe *.mp3 *.mp4 *.m4p *.wma *.temp *.acc *.cda *.mpeg *.mov *.wmv *.wma *.asx *.mpg *.asf *.wav *.m3u *.m4a *.mpg *.bak *.xbk /s REM ------ Change focus to drive D: data\Shared Data -------- REM REM Only enable script below if schedtask account has access and you want to delete these file types cd /d d:\"Data\Shared Data" del *.flv *.avi *.qt *.msi *.zip *.tmp *.exe *.mp3 *.mp4 *.m4p *.wma *.temp *.acc *.cda *.mpeg *.mov *.wmv *.wma *.asx *.mpg *.asf *.wav *.m3u *.m4a *.mpg *.bak *.xbk /s REM ------ Change focus to drive D: data\profiles\teaching staff to reduce profile size on logon-------- REM------- REM------- xml files added for deletion from profiles as long xml file names causing profiles to fail loading. REM------- cd /d d:\"Data\Profiles\teaching staff" del *.flv *.avi *.qt *.msi *.zip *.tmp *.exe *.mp3 *.mp4 *.m4p *.wma *.temp *.acc *.cda *.mpeg *.mov *.wmv *.wma *.asx *.mpg *.asf *.wav *.m3u *.m4a *.mpg *.bak *.xbk *.xml /s REM ------ Return focus to drive d: and exit ------ cd /d d:\ exit This script is for deleting from student folders. I do not allow students to have roaming profiles as this simplifies management of students. Place the script on the drive you want to run it from in my case it's drive D REM ---------- CHANGE FOCUS TO DRIVE D: AND MOVE TO STUDENTS HOME FOLDERS AND DELETE ILLEGAL FILES cd /d d:\"data\home folders\students" del *.flv *.3gp *.tmp *.exe *.mp3 *.stk *.piv *.ram *.mid *.mp4 *.tmp *.js *.acc *.zip *.lnk *.cda *.mov *.mpeg *.asx *.asf *.wav *.wma *.wmv *.m3u *.m4a *.mpg *.bak *.swf *.url /s > delhunt.log REM -------------RETURN TO D: AND EXIT cd /d d:\ exit Obviously the paths will be different for your server. make sure the paths are correct and ensure you end the script with the focus back on to the drive you started from and use the exit command to close the script as you don't want the script to jump drives and cause havoc on the system drive. Create a dedicated account ( something like schedtask) for running the script and give it the appropriate permissions and then assign the account to have full control over the folders you want it to access . Dont use your main domain or server administrator account as the password should be changed on a regular basis and when you change it if you've used the administrator account for your script the job will fail because it has the wrong password set in the scheduled task properties It's not the best batch filing you'll see but it works for me. Hope this is of some help Kili Edited June 14, 2010 by kili
kili Posted June 15, 2010 Posted June 15, 2010 d: cd \profiles for /d %%i in (*) do rd "%%i\cookies" /s /q Hi Steve , is it possible to adapt the above to delete profile folders from workstations where it generates profiles folders such as anyname anyname001 anyname002 anyname003 and so on. I have delete roaming profiles on log off set in GPO but of course this does not always work . I have psexec from sysinteranls which allows me to send to a command prompt to a list of workstations from a file. If I could adapt this for statement to delete profiles with certain strings of letters in them (anyname001 anyname002) it would help me with a few issues regarding profiles. for instance one individual has a hugh profile and has used over 50 different computers regards Kili
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now