Kaseya Community

Script to delete files in users folder?

  • I'm trying to figure out an easy way to delete everything in a users folder, without deleting the users folder itself.
    So with a structure like this:

    c:\users\gsmith
    c:\users\alincoln
    c:\users\jdoe
    etc... etc.

    I want to delete EVERYTHING under the users directory, with out deleting the named top level directory (gsmith, alincoln, etc)

    I have to clean out 2500+ folders. Any ideas would be greatly appreciated.

    Thanks,
    Jason

    Legacy Forum Name: Script to delete files in users folder?,
    Legacy Posted By Username: jasonmh
  • I started working on this a couple weeks ago. The idea was that is a laptop or computer was stolen I could run this script if it was ever turned on and accessed the internet.

    I have not had time to test it though but it should do what you are looking for and will not remove the folders..

    Let me know how it works out.

    Script Name: Delete User Files
    Script Description: Script to delete user files:
    XP/2000: c:\documents and settingsVista: c:\users\

    IF True
    THEN
    Execute Shell Command
    Parameter 1 : del /f /q /s c:\documents and setting\*.*
    Parameter 2 : 0
    OS Type : 8
    Execute Shell Command
    Parameter 1 : del /f /q /s c:\documents and setting\*.*
    Parameter 2 : 0
    OS Type : 3
    Execute Shell Command
    Parameter 1 : del /f /q /s c:\users\*.*
    Parameter 2 : 0
    OS Type : 10
    Write Script Log Entry
    Parameter 1 : Users files deleted
    OS Type : 10
    ELSE

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: mlnetcor
  • thank you very much, i'll give it a try today and post back.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: jasonmh
  • That worked really well. It left the subfolders (folders below the c:\users\user1\..), but it removed all the files in the subfolders, which was all I really needed. Thanks again.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: jasonmh
  • Could have also used:

    rmdir C:\Directory /S /Q

    Cheers,

    Greg

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: glipschitz
  • I had to do same task for other folders and I did a different method.
    K2 server

    I created a batch file, upload to Kserver and then have the script write , execute and delete batchfile. I found it to be faster (in writing terms) then writing agent procedures for doing the same thing.

    IDK if bandwidth is an issue since the batchfile is so small anyway.

    No idea if you can write in notepad and import in K2 for procedures, it probably would be faster.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Hasani