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
DEL /Q /Fto 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