Solved

Deleting Temporary Files using SCCM or GPO or something else.

Posted on 2015-01-14
10
1,366 Views
Last Modified: 2015-02-24
Does anyone have a way that they periodically delete temporary files on a machine via SCCM or GPO or another method. When I do a Disk Cleanup on some machines on occasion, the temporary files sometimes hit over 50GB. What is the easiest way to set a task to delete these on 1000+ machines periodically? BTW..this is not just for Temporary internet files. I would want it to delete all temp files including hidden files and read only files. This is on Windows 7.
0
Comment
Question by:prologic08
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40549886
I use CCleaner from Piriform.com and have a logoff script that automatically runs it.
0
 

Author Comment

by:prologic08
ID: 40549948
I cannot use CCleaner for this although I do use it personally. Thank you Gabriel.
0
 
LVL 13

Accepted Solution

by:
Gabriel Clifton earned 250 total points
ID: 40549989
How about using this as a logoff script

@echo off
cd /d %temp%
for /r %%a in (*.*) do (
del /f /q %~a
) >nul
cd /d "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files"
for /r %%b in (*.*) do (
del /f /q %~b
) >nul
cd /d "C:\Windows\Temp"
for /r %%b in (*.*) do (
del /f /q %~b
) >nul
cd /d "C:\Windows\Prefetch"
for /r %%b in (*.*) do (
del /f /q %~b
) >nul

Open in new window

0
Upcoming Webinar: Percona XtraDB Cluster 6/21 10am

Join Percona’s MySQL Practice Manager Kenny Gryp and QA Engineer, Ramesh Sivaraman as they present Percona XtraDB Cluster, Galera Cluster, MySQL Group Replication on Wednesday, June 21, 2017 at 10:00 am PDT / 1:00 pm EDT (UTC-7).

 
LVL 18

Assisted Solution

by:Mike T
Mike T earned 250 total points
ID: 40551128
Hi,

I don't have an existing method but I suggest a few.

1) Run a script using ConfigMgr using a task-sequence
2) Run a script using ConfigMgr using a package and set it to recur
3) use a GPO with same script

Gabriel's script is fine but I would avoid using a login script. People are trying to avoid that as it stalls the login. People are impatient and want to get to their desktop!

For the same reason I would avoid using a machine startup GPO.

Personally I like option (1) as it's controllable, has logging and you can schedule it. A TS is slightly more versatile than a package because you can add WMI conditions etc. and I just find it more user-friendly than package rules.

Mike
0
 

Author Comment

by:prologic08
ID: 40554238
What I am thinking is using Gabriel's script and making a task sequence for each folder to delete and running it monthly.
0
 

Author Comment

by:prologic08
ID: 40554239
Do you think it is ok to delete the ccmcache as well?
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40554328
From what I know about ccmcache is that the ccm server should automatically clear the cache. If you manually clear the cache and the ccm server purposely left something there, it could cause issues.
0
 

Author Comment

by:prologic08
ID: 40554360
Gotcha. My assumption is that any files that are put there and are still being used are caused by the way I create the script. For instance, I was creating a script that dropped an icon on the desktop. I accidentally added the icon to the ccmcache instead of copying it to another location and when I deleted the folder in the ccmcache, the icon stopped showing.
0
 

Author Comment

by:prologic08
ID: 40594340
So I ultimately decided to go with a Task Sequence in SCCM. But..of course..I am having problems with it deleting in Windows 8.1. I have no issue in Windows 7.

I created 6 tasks to run a command line.

Task 1: Delete Prefetch Directories
CMD.exe /S /C rmdir "C:\Windows\PreFetch\ReadyBoot" /s/q

Open in new window


Task 2: Delete Prefetch FIles
CMD.exe /S /C del "C:\Windows\PreFetch\*" /s/q

Open in new window


Task 3: Delete Local Temp Files
CMD.exe /S /C for /f "delims=|" %f in ('dir /B /A:D-H-R c:\users') do del /s /q "C:\Users\%f\AppData\Local\Temp\*"

Open in new window


Task 4: Delete Windows Temp Files
CMD.exe /S /C del "C:\Windows\temp\*" /s/q

Open in new window


Task 5: Delete Temporary Internet Files - W7
CMD.exe /S /C for /f "delims=|" %f in ('dir /B /A:D-H-R c:\users') do del /s /q "C:\Users\%f\AppData\Local\Microsoft\Windows\Temporary Internet Files\*"

Open in new window


Task 6: Delete Temporary Internet Files - W8.1
CMD.exe /S /C for /f "delims=|" %f in ('dir /B /A:D-H-R c:\users') do del /s /q "C:\Users\%f\AppData\Local\Microsoft\Windows\INetCache\*"

Open in new window



This deletes everything correctly in Win 7 but deletes nothing in Win 8. Would someone be able to modify the command lines to allow it to delete in both Win7 and Win 8? I assume I could have made this look cleaner and shorter.. There is no need to have multiple tasks, I just did it cause I didn't know any other way..

Any help is greatly appreciated.
0
 
LVL 18

Expert Comment

by:Mike T
ID: 40598034
Hi,

I can understand you want to spring clean machines but it seems you've got over-zealous. In general, anything that is cache-based is best left alone. You've already found that with ccmcache. It also applies to prefretch. Do NOT clean them out. It's a complete urban myth from XP days. I expect W7, 8 and later are either the same or more efficient.

C:\Windows\PreFetch\ReadyBoot"   - leave alone
C:\Windows\PreFetch                         - leave alone

C:\Users\%f\AppData\Local\Temp\*    - ok
C:\Windows\temp\*"                               - ok              
C:\Users\%f\AppData\Local\Microsoft\Windows\Temporary Internet Files\*     - better to fix that with a GPO

For a good article on pre-fetch, please see here:
http://www.edbott.com/weblog/2005/06/one-more-time-do-not-clean-out-your-prefetch-folder/
It's 2005 but as valid today as it ever was.

I don't have W8 to try testing the commands, so can't help on that. Do the commands work manually?

Mike
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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