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