Do you ever wish you could autodefrag multiple computers at night while using Windows Scheduling? On the surface it seems it would be a very simple task, and provided your environment is setup correctly, it is easy. First of all, your target workstations must be registered. Second of all you must have a Wake On Lan policy. Third the ZENworks agents must be installed and running on the client.
First things first. We need to create a scheduled task on every XP computer on which you plan to run the defrag. So I created a ZENworks App that would call the schtasks.exe and put in the proper parameters to create the scheduled task. Proper parameters consist of:
- Administrator Username
- Administrator Password
- Schedule of the task
- Name of the Task
- Time to run
- What you want to run
Then I needed a batch file to actually run the defrag and shutdown the computer afterwards. This is what the scheduled task calls (aedfrg.bat ). Now we have a scheduled task that has the computer start a batch file which calls the defrag utility, then defrags the computer and shuts it down when it’s finished.
With the computer ready to defrag automatically every night at 4:23AM (see below example) we have to make sure the computer is on so this can happen. I do this by creating a Wake On Lan policy under the server’s policy package. This policy wakes up the target group every morning at 4:00AM. One more thing, if you are afraid that you will not have enough time to run the defrag before the users come in for work, set it up for Friday to run over the weekend. Once the fragmentation level goes down, it takes very little time to complete the defrag.
ZENworks App Object
Path to file:
Either copy the schtasks.exe to somewhere on your network or call it directly from the workstation. I copied to the network.
/create /ru administrator /rp ?YOURPASSWORD? /sc daily /tn aedfrg /st 04:23:00 /tr c:\aedfrg.bat
I have also checked the Run Application Once (if you make a change to the batch file, just change the version of the NAL object).
I run it as Unsecure System User, and hidden.
Then under Distribution Options at Application Files, I set it to copy the batch file from the network to the root of the user’s C Drive, and only copy if the file is newer.
Batch File (aedfrg.bat )
defrag c: -f shutdown -s -t 15 -c "Defrag Complete Shutting Down"
If you have any questions you may contact Denys at email@example.com
This could be useful if you feel the need to defrag your machines frequently, but there are some things to be aware of:
Secondly, the method described in this tip should work, but it’s possible to perform the same function without the need for an application object or a 3rd-party tool. ZENworks provides the ability to add to the workstation scheduler (installed as part of the |ZENworks agent), and you can create a scheduled action that runs both of these items in a workstation policy:
Note that I have the box “run items in order listed” checked, to ensure they run sequentially.
Set the schedule to run when you’d like it to take place, and set the impersonation to “system”.