Kaseya Community

Defrag

  • defrag.zip
    The two scripts work together. The first script, Defrag Analyze, will analyze volume C and pass the results to a variable.

    The second script will see if the variable from the analyze scripts "Contains", (new in version 4.4) a message that the volume needs to be defragmented. If it does, it will defrag, log the results and send a message.

    You will need to change the e-mail address. Obvious but, if you want the script to work with other volumes, just change the parameter and "save as".






    Legacy Forum Name: Defrag,
    Legacy Posted By Username: jimalves

  • Another great example in running child script from a Parent script:

    In this example you are only able to run the XP version of Defrag. The consistency is great... Thanks MS. SO you will have to edit the above script from Jim, run part of the script on windows XP machines and then run the other part of the script on windows 2000, (running autodefrag).

    The problem with this is that you cant run this program if the user is logged off.

    Furthermore you cant tellif the script did anything on the windows2000box because there is not a logging function.

    Oh and you will have to run the script every time... you cant create checks and balances with AutoDefrag. (if a drive is 1% fragmented it does not care it will still run.)

    I have tried to run contig but have been unsuccessful in creating a script that is SMART


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: sourceminer
  • I servers with multiple drives (c:, E:, F: etc.) and want to be able to defrag all of them with one generic script that is not computer specific. Is there any way to getall of the drives on a computer?

    David Johnson


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: effective
  • Do you have a script that will get all local disks on a server or workstations?

    For example, if server has C:, D: and E:, how can I get the drive letters that's available on that server?

    Thansks.

    Hang


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: advancedse
  • We finally came up with a set of scripts and utilities that will let us check and (if "You should defragment this volume") defrag all fixed disks at an endpoint. We have two VB scripts, a couple of GNU utils and three Kaseya scripts. For all of that, it's still rather elegant (compared to our earlier efforts).

    If there's interest, I'll ZIP the whole package and post to the thread.


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: GreyDuck
  • GreyDuck wrote:
    We finally came up with a set of scripts and utilities that will let us check and (if "You should defragment this volume") defrag all fixed disks at an endpoint. We have two VB scripts, a couple of GNU utils and three Kaseya scripts. For all of that, it's still rather elegant (compared to our earlier efforts).

    If there's interest, I'll ZIP the whole package and post to the thread.



    We would love to see it. Thank You


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: far182
  • Master Defrag Scripts.zip
    Ask, and ye shall receive. I included a (moderately wordy) README.txt which contains the following (for use when you don't want to keep a forum window open just to play with these scripts, of course):

    * These scripts only work on systems where the command-line defrag is available. It will bail (and write to the script log accordingly) on older systems. If you want to script defrag routines for 2K or 98 or what-have-you, you'll have to come up with another method. This isn't an issue for ~95% of our install base, so we're probably not going to bother.

    * The temp directory is hard-coded. If you're clever enough to make the VBS files grab a meaningful temp directory, be my guest. (Yes, I know how it's done but it gave me fits trying to use the technique when using Run As System in my Execute Command lines. I am not a VBS guru.)

    * On a related note: If I happened to miss a reference to "C:\roi" in any of these files... well, then Vim's search-and-replace isn't working as advertised, and I get sent to the back of the class for lack of proofreading-fu.

    * Don't forget to tidy up the references to called scripts, and import them in order: MAIN Launcher, then Loop, then Sub Process. After that you can rename them to your heart's content, of course.

    * Yes, scripts can loop if you put in a delay and set it to call itself. You'll notice that I'm careful to check, not for the existence of a file, but for the presence of a ":" character. Once there are no more C:, D: and so forth in the FixedDisks text, the looping script will cease re-scheduling. Also notice the oh-so-clever .25 Minutes, which has the advantage of catching the agent check-in cycle more often than not. (Who wants to wait up to 90 seconds? Not me.)

    * Scripts can time out. This means that large server drives with much defragmentation to take care of will probably need a more direct approach. This script structure is more useful for smaller devices and/or regular maintenance than for major repairs.

    * Why the script log? So we can create reports, of course! We can even add "defrag analysis" to the Executive Summary! To learn how, just send $99.95 to the address on your screen. (Or, ask in the forums. It's your call.)

    * If you have questions, improvements, or just want to kibbutz, feel free to reply in the forum thread or email me directly: kkerezman@roinc.com.

    * Share and enjoy!


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: GreyDuck
  • Very nice. Thanks for sharing.

    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: vplaza
  • Nice script there. We have been scheduling defrags for some time but only on system partitions and data (non-database) partitions. We do the same thing of analyzing first to see if it needs defragmenting and reporting the analyzed data and the defrag (if needed) data to the logs for reporting.. Iwill have to give this script a look though..

    I have attached a screen shot of the exec reports that we run.. As you can see we report on spyware, viruses, and the defrag.. We base the percentage fromdefrag a search of a script we run and looking for a Success THEN statement.. In the script if it is a THEN we know that a defrag did not need to be ran.. If it is a Success ELSE, we know it had to be run which means the drive had to be defragmented..

    God Bless,

    Marty


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: MissingLink
  • Could you please post your script or email to me directly at hang@advancedse.com

    Thanks in advanced.

    HangBig Smile


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: advancedse
  • Nice script GreyDuck, I liked your idea of using VBscript to automatically select only fixed disks and so I was inspired to write a new defrag script of my ownthat you can find here:

    http://www.securemycompany.com/forum/viewtopic.php?t=45

    It consists of a single VBS file launched via a single Kaseya script that will analyze all fixed drives on a remote system, defrag them if necessary and return results via Get Files, although it is easy to modify the Kaseya script to get this data in other ways (eg. script log, email).

    Yes, I know, unfortunatelly it still relies on the ol' defrag.exe utility found only on XP/2003. I guess there is always DIRMS for all of you 98/2000 folks out there.For 2003 systems it is actually possible to access the defragmenter via WMI (http://www.microsoft.com/technet/scriptcenter/topics/win2003/defrag.mspx) but this is obviously limited only to servers.

    Enjoy,

    -Ed


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: bellcpa
  • Can you post the VB script here (defragalldrives)? When I try to open it or download it on your forum, it wraps everything.

    Thanks!


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: billmccl
  • Ed,

    I can't take credit for the VBscript idea; that was my boss's contribution. We actually had something of an informal competition going to see whose defrag script set was better. The final product is a mixture of our two approaches, mine using GNU utils and his using VBscripts.

    The one thing we get from our system that I'm not seeing in yours is the ability to add defrags to the Executive Summary (or to create a standalone report). That's why we worked so hard to get individual drives' defrag output into the Script Log. However, there's something to be said for the elegance of a single script! The only reason we didn't go with my boss's original master VBscript is that we were very keen to find new things for the Executive Summary.

    Stuff like this is why I like coming to work in the morning...

    - Karel


    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: GreyDuck
  • defragalldrives.txt
    GreyDuck:

    I see your point about executive summary, if you really need to report on each drive as a separate script log entry, Kaseya script looping is required (how aboutthat FOR/WHILE functionality in the script log Kaseya?). May I ask what kind of defrag info you are looking for in the exec summary (how many drives were actually analyzed, defragmented)?

    billmccl:

    I have attched defragalldrives.txt, rename the extension to vbs. Also, if you right-click it in the forum and do "Save as" it should save it unwrapped.

    -Ed




    Legacy Forum Name: System Administration Scripts,
    Legacy Posted By Username: bellcpa
  • At this point, am I correct in assuming there is no way around having a user logged into a server or workstations for any of these scripts to work?

    How do you cope with this limitation when trying to do regular defrags?






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