1

I work as an IT techinician in a company that has roughly 600 Windows 7 laptop, distribuited in 8 countries. We use Microsoft SCCM 2012 to manage the clients.

We have a recurring problem with the hard disks, they tend to accumulate hundreds of gigabyte in their c:\windows\temp directory, and since these files are created by processes with administrator privileges, users cannot clean them.

So i have created this batch that checks the free disk percentage and if it's smaller than 30% it proceeds with the cleanup:

@echo off
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='C:'" get FreeSpace /format:value`) do set FreeSpace=%%x
for /f "usebackq delims== tokens=2" %%x in (`wmic logicaldisk where "DeviceID='C:'" get Size /format:value`) do set Size=%%x
set FreeMB=%FreeSpace:~0,-6%
set SizeMB=%Size:~0,-6%
set /a Percentage=100 * FreeMB / SizeMB

IF %percentage% LSS 30  del c:\windows\temp\*.* /Q

this script will be run through SCCM2012 and should be run on every client once a month.

While this batch will surely work, does anyone have a more elegant solution?

Thank you

Alfa Taurus
  • 163
  • 1
  • 5
  • 1
    I'd run the deletion of the temp folders at logon and/or logoff if possible rather than once a month actually. If they are logging on or off, then there should not be anything using the temp folder. Use `DEL /Q /F` to do it forcefully too. Check over parts of this script here you may find helpful as well for getting disk space back just in case you see anything relevant it's as simple as looking it over I suppose.https://superuser.com/questions/1187299/windows-7-cleanup-before-clonezilla-backup/1187334#1187334 – Vomit IT - Chunky Mess Style Oct 04 '17 at 13:12
  • 1
    Have you identified the application that is generating hundreds of GBs worth of temporary user data? – Ramhound Oct 04 '17 at 14:14
  • Yes, is SCCM, but since we are an external technical firm hired only for maintenance, other than reporting the problem we can't solve it. – Alfa Taurus Oct 04 '17 at 14:18

0 Answers0