Kaseya Community

Automatic Disk Clean-up and Defrag

  • Hello all,

    I have bit of a difficult request that I am having trouble even getting started with.

    I would like to write a script that does the following:

    1: check the amount of free space on workstation
    2: IF disk space is below 10%, run disk clean-up
    3: re-check the amount of free space on workstation
    4: IF disk space is below 10%, run disk defrag
    5: re-check the amount of free space on workstation
    6: IF disk space is still below 10%, created a helpdesk ticket

    It sounds easy enough but I am novice script writer at best and am having the biggest problem with getting the free space variable and using that variable throughout the script.

    Thanks!!

    Legacy Forum Name: Automatic Disk Clean-up and Defrag,
    Legacy Posted By Username: alanwalt@fdlrez.com
  • I do have something similar, but I cannot share this one (sorry, I can't give everything away.)

    Two comments on this, though:
    1) It's not generally recommended to defrag a drive if there is less than 15% of free space available. There simply wouldn't be enough space to move large files around to make the necessary space to keep everything together.
    2) defragmenting a drive doesn't recover any space.

    Hints:
    Use one of the included monitors to keep taps on freespace on the C: drive.
    Set the monitor to run a CCleaner script (or something similar) to free up space. Have this script execute another script to check how much disk space is available (this is the tricky part. I solved this with a VBScript. Have this script write an event log entry if there is still less than 10% free space on the drive.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Lmhansen
  • Depends how big the disks are really. 120gb+ should be fine to defrag @ 10%

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Dean
  • I know this is an old thread, but thought I would add it. When considering a defrag, I recommend using Contig from SysInternals. Granted it is only a file level defrag tool, but it does a very nice job -- much nicer then a native Microsoft defrag.

    On a new machine, I run it nightly for a few nights. By that time you can drop back to running it weekly to keep things clean.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: DavePurscell
  • DavePurscell
    I know this is an old thread, but thought I would add it. When considering a defrag, I recommend using Contig from SysInternals. Granted it is only a file level defrag tool, but it does a very nice job -- much nicer then a native Microsoft defrag.

    On a new machine, I run it nightly for a few nights. By that time you can drop back to running it weekly to keep things clean.


    Hi Dave,

    would it possible for you to share and post your script?

    thanks alot.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JeffD
  • Lmhansen
    I do have something similar, but I cannot share this one (sorry, I can't give everything away.)

    Two comments on this, though:
    1) It's not generally recommended to defrag a drive if there is less than 15% of free space available. There simply wouldn't be enough space to move large files around to make the necessary space to keep everything together.
    2) defragmenting a drive doesn't recover any space.

    Hints:
    Use one of the included monitors to keep taps on freespace on the C: drive.
    Set the monitor to run a CCleaner script (or something similar) to free up space. Have this script execute another script to check how much disk space is available (this is the tricky part. I solved this with a VBScript. Have this script write an event log entry if there is still less than 10% free space on the drive.


    Hi Dave

    I am new to Kaseya and looking for similar scripts.

    I would appreciate any more help on how to perform the above mentioned function, along with some script examples if anything.

    Thanks.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: dhufford
  • Have to disagree with Dave on his software choice on this occassion I am afraid, best defrag tool by a mile is Defraggler which is free and made by Piriform (CCleaner creators).

    I have and install script for it but to be honest all you really need to know for installation is Silent Installation can be easily achieved using /S.

    Have not got round to scripting the job yet though.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: stu_u2k
  • Defraggler also has a portable version that doesn't require an installation. I would just dump that in the agent directory and execute it from there rather than installing it.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: drodden
  • Yes this is true, but somehow I prefer it installed, don't ask why please because I couldn't tell you, I just do. Stick out tongue

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