Kaseya Community

Scripts to clean up user profiles

  • One of our clients is a school where user's are rotated out as they graduate, and this ends up leaving behind a lot of old profiles on the machines for users that no longer exist, etc. These profiles end up taking up a lot of space on the machine hard drives, and we needed a way to safely clear this up. So I came up with the following script.

    Note: You will need to download and add the following files to your KServer.
    touch.exe
    - from the unixutils package http://unxutils.sf.net, note the download from this info page is broken, you can get the actual zip file here ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip

    delprof.exe - From the windows resource kit.
    http://www.microsoft.com/downloads/details.aspx?FamilyID=901A9B95-6063-4462-8150-360394E98E1E&displaylang=en

    Script Name: Clean up old user profiles.
    Script Description: This script will remove any local user profiles that have not been accessed in the last 365 days. This script will only work correctly on Windows 2000 or better, and uses touch.exe from http://unxutils.sf.net and the delprof.exe windows resource kit utility.

    If there are any user profiles other than administrator that you absolutely *don't* want to remove copy step 4 and change the path to match the correct one for the user profile you want to leave alone.

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : tempPath
    OS Type : 1
    Write File
    Parameter 1 : #tempPath#\touch.exe
    Parameter 2 : VSASharedFiles\touch.exe
    OS Type : 1
    Write File
    Parameter 1 : #tempPath#\delprof.exe
    Parameter 2 : VSASharedFiles\delprof.exe
    OS Type : 1
    Execute File
    Parameter 1 : #tempPath#\touch.exe
    Parameter 2 : "%SYSTEMDRIVE%\Documents and Settings\Administrator\NTUSER.DAT
    Parameter 3 : 3
    OS Type : 1
    Execute Shell Command
    Parameter 1 : #tempPath#\delprof.exe /Q /D:365 >> #tempPath#\proflog.txt
    Parameter 2 : 1
    OS Type : 1
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #tempPath#\proflog.txt
    Parameter 3 : profLog
    OS Type : 1
    Write Script Log Entry
    Parameter 1 : #profLog#
    OS Type : 1
    Delete File
    Parameter 1 : #tempPath#\delprof.exe
    OS Type : 1
    Delete File
    Parameter 1 : #tempPath#\touch.exe
    OS Type : 1
    Delete File
    Parameter 1 : #tempPath#\proflog.txt
    OS Type : 1
    ELSE



    Legacy Forum Name: Scripts to clean up user profiles,
    Legacy Posted By Username: Jonathan
  • Here is another version of the script that simply clears cached roaming profiles from a computer. We needed this one because we hadn't originally enabled the deletion of cached profiles in Group Policy, and later when we went back and did so, we need some way of clearing out all those cached profiles from the machines so it could get a fresh start. It also needs touch.exe and delprof.exe.

    Script Name: Clear cached roaming profiles.
    Script Description: This script can be used to clear cached roaming profiles from a system. It requires touch.exe from the UnixUtils project ("http://unxutils.sf.net") and delprof.exe from the windows resource kit.

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : tempPath
    OS Type : 1
    Write File
    Parameter 1 : #tempPath#\touch.exe
    Parameter 2 : VSASharedFiles\touch.exe
    OS Type : 1
    Write File
    Parameter 1 : #tempPath#\delprof.exe
    Parameter 2 : VSASharedFiles\delprof.exe
    OS Type : 1
    Execute Shell Command
    Parameter 1 : #tempPath#\delprof.exe /Q /R >> #tempPath#\proflog.txt
    Parameter 2 : 1
    OS Type : 1
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #tempPath#\proflog.txt
    Parameter 3 : profLog
    OS Type : 1
    Write Script Log Entry
    Parameter 1 : #profLog#
    OS Type : 1
    Delete File
    Parameter 1 : #tempPath#\delprof.exe
    OS Type : 1
    Delete File
    Parameter 1 : #tempPath#\touch.exe
    OS Type : 1
    Delete File
    Parameter 1 : #tempPath#\proflog.txt
    OS Type : 1
    ELSE



    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: Jonathan
  • rue.JPG
    When I import this script, I receive the following error:

    "The IF statement rue is not valid"

    I assure anyone reading this post that I didn't cut off the "T" in True. Also the letters, "rue," doesn't appear anywhere else in the script. I also have the two files that are needed in the correct directory on the Kaseya server.

    Any ideas or am I Kaseya Challenged?


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: EDavis
  • The issue is that you aren't copying enough of the text out to import...

    If you copy everything from Script name:.... Down to the end then it will import just fine.



    Basically get everything in the white box.


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: Jonathan