• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4582
  • Last Modified:

Disk Cleanup for all user profiles on Terminal Server - Windows 2008

I would like to be able to empty all temp directories for all user profiles on our Terminal Server which is running Windows 2008 R2. How do I action this? When I run disk cleanup as the Administrator it only relates to the Administrator profile. I would really like perform some sort of disk cleanup that will affect all the profiles on the Terminal Server.

Any ideas?

Thank you
  • 4
1 Solution
There is no single command or folder you can erase to do all profiles on Terminal Servers.  What you'd have to do is list all the folders in the users area, and then systematically remove all temp folders for each directory.

Example : Dir list of C:\Users reveals 5 users named User1, User2, User3, User4, User5

Then, you'd delete the contents of the 5 following folders.


Be careful though - If this folder is missing, it will cause issues - only delete the contents of the folders, not the folders themselves.

You can try this code
On Error Resume Next
    Dim fs, f, f1, fc, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder("c:\users\")
    Set fc = f.SubFolders
    For Each f1 in fc
        temp_path="c:\users\"& f1.Name &"\AppData\Local\Temp\4\*.*"
        fso.DeleteFile temp_path, True 

Open in new window

the_omnificAuthor Commented:

Please find attached
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

the_omnificAuthor Commented:
Lester_Clayton > You mean don't delete the temp folder itself C:\Users\User1\AppData\Local\Temp but we can delete everything inside it including subfolders without causing issues ?
the_omnificAuthor Commented:
Thank you for your input guys but I have opted to use CCleaner to run in silent mode in everyone's start-up.
the_omnificAuthor Commented:
I have used a different method that I am happy with.
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.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now