/bundles/itninjaweb/img/Breadcrumb_cap_w.png

Hello all,

I am new to the KACE world. I am hoping the community can assist me. I need a script that will do the following:


Delete any file or folder that is within any temp folder (including the temp folders in the users profile i.e., C:\Users\%USERNAME%\AppData\Local\Temp) need to be deleted. Also all files and subĀ folders within the download folder. I work in an environment where we need the ability to clean these folders out on a regular schedule.

I am terrible with scripting but would am willing to learn. Any assistance will be appreciated.

Mr. Newbie!


2 Comments   [ - ] Hide Comments

Comments

  • Are you sure you want to delete the files for currently logged in users?
  • Maybe I wasn't as clear as I needed to be ;). Any file or folder that is within any temp folder (including the temp folders in the users profile i.e., C:\Users\%USERNAME%\AppData\Local\Temp) need to be deleted. Also all files and folder within the downloads folder. Work in an environment where we need the ability to clean these folders out on a regular schedule.
Please log in to comment

Answer this question or Comment on this question for clarity

Answers

0
Here is a Batch file solution:

(
    for /D %%x in ("C:\Users\*") do ( 
  del /f /q "%%x\AppData\Local\Temp\*.*" 
    )
)
Answered 05/19/2017 by: Desktop Jockey
Second Degree Green Belt

  • That kind of works. It deleted most of the files within the temp folder but left all subfolders and files within. I have since figured out how to delete the files within the subfolders. I still need to figure out how to suppress everything from showing on the screen to the user and to also delete everything from the windows temp folder. I appreciate everyone's help.

    (

    for /D %%x in ("C:\Users\*") do (

    del /f /s /q "%%x\AppData\LocalLow\Temp\*.*"
    del /f /s /q "%%x\AppData\Local\Temp\*.*"


    )
    • If you are running this from a Kace Script then it will be silent by default.

      Also if you are having issues with the sub directories, you can add a rmdir command to that process.
      • I did read about the rmdir command but haven't had success with it yet. Scripting is not my strong suite. Appreciate the responses.
Please log in to comment