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.
Answers (5)
this runs once a month on all (windows) machines:
Comments:
-
I'm trying to set this up but keeps failing. Just a normal "Launch a program"? How do I set this script up? - bkieft 1 year ago
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
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)
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..
Comments:
-
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:
C:\Users\{username}\AppData\Local
When the a Kace script is running the default is the System account so the the localappdata folder will be:
C:\Windows\system32\config\systemprofile\AppData\Local
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 1 year ago