I got a great question from Brian this week:
“Is there a quick way to delete the temp files for all user profiles?
We have some PC’s that many users logon to and over a period of time there can be many thousands of temp files in each users profile.”
A simple way to do this is to write a script that will go through all the profiles.
Where do we start?
Well, first we want to get a list of all folders under “C:\Documents and Settings”
This will give us a list of the root user profile folders.
From there, we need to enumerate all the files and folders under this path of each profile:
"C:\Documents and Settings\[username]\AppData\Local\Temp"
Now that we have that list of files, we can simply delete them to clear out all the temp files.
Sounds easy, but it does require a little bit of work in VB Script. The script I built follows what I said, but it also automatically detects “C:\Users” used under Windows 8, and 2012.
To delete temp files in all profiles you need to run it as an administrator, like this from the command line:
Careful, since once you start the script – it will quickly delete those temp files:
You might want to schedule this one as a task that runs on a Sunday night.
You can get a copy of it here:
Remember to rename it to .vbs 🙂
One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools