What scripts do you use to clean up hard drive space on your Windows machines?

I’m exploring the automating of freeing up hard drive space on our Windows pcs using Kace SMA (k1000) scripting. Are there scripts any of you have used yourself or would recommend to one looking to free up HD space on remote (kace agent) machines?

Thanks for your time.

0 Comments   [ + ] Show comments

Answers (5)

Answer Summary:
Posted by: Nico_K 4 months ago
Red Belt

this runs once a month on all (windows) machines:

  1. Launch “$(KACE_SYS_DIR)\cmd.exe” with params “/c rd c:\windows\temp\* /s /q”.trashcan-icon.png
  2. Launch “$(KACE_SYS_DIR)\cmd.exe” with params “/c rd $(KACE_DATA_DIR)\patches\* /s /q

  • I'm trying to set this up but keeps failing. Just a normal "Launch a program"? How do I set this script up? - bkieft 3 months ago
Posted by: rodwyer 4 months ago
Senior Yellow Belt

Nice. That gives me a good entry point and a model to add further scripts. Thanks!

Posted by: JordanNolan 4 months ago
10th Degree Black Belt

Top Answer

I do something similar, but use a GPO.  I use the Shutdown event for computer and LogOff event for user so I do not clear any temp files in use:

Under Computer -> Policy -> Windows Settings -> Scripts I have a Shutdown.bat script

del /q "C:\Windows\Temp\*"
FOR /D %%p IN ("C:\Windows\Temp\*.*") DO rmdir "%%p" /s /q

Under User -> Policy -> Windows Settings -> Logoff I have a Logoff.bat script

del /q "%localappdata%\Temp\*"
FOR /D %%p IN ("%localappdata%\Temp\*.*") DO rmdir "%%p" /s /q

I also have a scheduled task set to run monthly to perform a diskcheck.
CMD.exe /c "ECHO Y|chkdsk c: /f"(You need the ECHO Y to tell the chkdsk command Yes to perform the check on the next reboot)
Posted by: rodwyer 4 months ago
Senior Yellow Belt

Thanks JordanNolan! I tried using some of your script with my Kace script but it appears that the variable localappdata doesn't map to the logged in user on the pc but runs in the kace folder. Heh, maybe that's why you run it via GPO instead of directly from Kace?

Otherwise I used it and will run it entering the full path sans variables but if said path doesn't match with some users it won't obvious work then. Hmm..

  • Hi Rodwyer,

    Yes, that is why I use the GPO. When running the scripts, be sure you keep in mind the perspective of how the script is being run. When running the User settings of a GPO, the %localappdata% variable is from the perspective of the user and will be:


    When the a Kace script is running the default is the System account so the the localappdata folder will be:


    If you change the script settings so it is only run with Windows clients and set the script to run as Logged-In User, the %localappdata% variable will run correctly. - JordanNolan 4 months ago
Posted by: MikeC: 4 months ago
White Belt

Do you have a ton of old user profiles that you could delete? I've got a GPO set to delete old profiles after X days on select computers. Admin Templates -> System/User Profiles -> Delete user profiles older than a specified number of days. Might not work for you, but worth mentioning.

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ