Kaseya Community

Cleaning Temp Files/Automation Question

This question is not answered

Hello - currently we use scripts to clean temp files, or scripts to do various tasks. However, it doesnt seem that it is working properly or automated. We have to deal a lot with computer clean ups due to free space alarms. Upon emailing Kaseya - they said that we did not have our workstations setup under the Systems Management Configuration - Workstation maintenance. Does everyone use the workstation maintenance area option? If we don't have that setup for any of our x amount of clients - is it easy to migrate them to that settings or what would be the best way to approach it? How we use Kaseya now - it doesn't feel very automated, or not as much as I believe it should be and we are looking for some insight on how to be more efficient and to let Kaseya take care of certain automated things. Any suggestions would be appreciated.

All Replies
  • Hello MollyRSnyder,
    I would be answering to the part where you say that using scripts does not seem to work properly.
    We schedule an Agent Procedure with a very simple single Powershell step.
    No need to copy script files to each endpoint.

    Check this below please:

    try { Remove-Item (@('C:\Temp', 'C:\Windows\Temp\*', 'C:\Documents and Settings\*\Local Settings\temp\*', 'C:\Users\*\Appdata\Local\Temp\*')) -force -recurse -ErrorAction SilentlyContinue} catch {}


    Interesting note is that by including paths such as this one:

    C:\Users\*\Appdata\Local\Temp\*”

    it will clean the temp of EVERY profile stored in the machine (note the asterisk after c:\users\ ).

    You can add other directories you want to clean by adding paths to the array in the first parameter of the Remove-Item function.

    Example (I added c:\temp")

    try { Remove-Item (@('C:\Temp', 'C:\Windows\Temp\*', 'C:\Documents and Settings\*\Local Settings\temp\*', 'C:\Users\*\Appdata\Local\Temp\*')) -force -recurse -ErrorAction SilentlyContinue} catch {}

    The try - catch is there on top of the "SilentlyContinue" to intercept the last error that would be otherwise output anyway regardless of the setting of ErrorAction.
    Reason is that sometimes there are locked files in the temp directories that need to be skip without error (and continue to clean the other files that can be cleaned).

    The agent procedure can be as simple as below and fast to execute.

    If you schedule this say.. weekly you would keep things clean.

    Procedure CleanTempFiles.xml


    Best Regards



    changed to single quote from open / close quoes, added exported procedure to make things even easier.
    [edited by: Alessandro Di Marco at 3:26 PM (GMT -7) on May 17, 2016]
  • we use ccleaner to run cleanups like this

    www.piriform.com/.../advanced-usage

  • FYI In the example the quotations are wrong and it wasn't showing errors in the Procedure unless I manually ran it, here it is corrected (it is correct in the screenshot though):

    try { Remove-Item (@("C:\Temp", "C:\Windows\Temp\*”, “C:\Documents and Settings\*\Local Settings\temp\*”, “C:\Users\*\Appdata\Local\Temp\*”)) -force -recurse -ErrorAction SilentlyContinue} catch {}

  • Hello Kuuser,

    Good Catch.

    The first script and screenshot were correct, but the second script after I added the c:\temp directory in the array had incorrect quotes.

    I have edited my post to correct the issue.

    Thanks

    Best Regards

  • Actually that wouldn't have worked either. The original poster used special quotes which would have probably worked but mine didn't work until I changed to single quotes:

    try { Remove-Item (@('C:\Temp', 'C:\Windows\Temp\*', 'C:\Documents and Settings\*\Local Settings\temp\*', 'C:\Users\*\Appdata\Local\Temp\*')) -force -recurse -ErrorAction SilentlyContinue} catch {}

  • I think your second and third quotes have to be the special type as well or it won't work -- or just use single quotes throughout.  



    fixed word
    [edited by: kuuser at 3:09 PM (GMT -7) on May 17, 2016]
  • I changed from open / close quotes (the "special" quotes you are referring to) to single quotes.

    I also added an procedure export so one does not even have to think about quotes and can just import it :-)

    I think this should make it really easy.

  • we used to use ccleaner, but it trashes a few things we want to keep such as pinned docs in Office. I know you can exclude office through the .INI file, however the syntax for this isn't published.

    I want to exclude ALL office versions [2000,XP,2003,2007,2010,2013,2016 and future].

    Are you customizing ccleaner at all? and if so, Can you share your cleaner.ini?

  • Hello Craig,

    Probably this is obvious and you have already tried that, but did you check the Options -> Advanced -> Save All Settings to INI file?

    Once that's checked, everything you can do in the user interface will be saved in the Ini file that you can later on distribute along with ccleaner if you wish to.

    File Exclusions, Registry Exclusions, all is saved to the ini file.

    On a side note, if you like to clean a lot using ccleaner a nice pre-made ini file is here.

    http://www.winapp2.com

    Some guys have build a super gigantic ini file to clean so much stuff to lose count and a batch file to run first to make the ini relevant to a target PC (so CCleaner starts faster).

    May be inside this ini file you may also find the techniques you are looking for.

    Best Regards