Defragmenting computers remotely

How to use PSExec to run a defrag task against a remote computer.

If you are a network administrator, you may have wondered if there was a way to remotely defrag your workstations.  Professional tools like O&O Defrag Enterprise provides this ability, but if you are on a budget, here is an alternative.

You may have already read the article on defragmenting tools for Windows, and will have seen some useful command lines that allow you to schedule a defrag using the builtin Windows defrag command.

What I am going to show you in this article is the ability to perform an On-Demand, remote defrag.  To do this we are going to use the PSEXEC tool from sysinternals. (www.sysinternals.com/Utilities/PsExec.html)

PSEXEC is a wonderful tool, that lets an administrator perform remote management tasks on Windows Workstations and Servers.  There are many command line options and parameters that make this tool very powerful indeed.

The tool has the ability to copy files onto the target workstation, giving the administrator the ability to deploy and run a utility application.

PSEXEC can also run commands against a whole domain or workgroup, by specifying * as a computer name.  Of course this can be quite dangerous, so I would advise against doing this.

I am going to assume that you have downloaded and extracted the PSEXEC tool onto your server or admin workstation in a folder called C:\\Remote Management.  I am also going to assume that your Windows computer have the Windows Firewall switched off.

Create a new file with Notepad and save it in the C:\\Remote Management folder as RemoteDefrag.bat.  Remember to change the type option from Text files to All files on the Notepad save dialog, otherwise you will end up with a file called RemoteDefrag.bat.txt that will only open in Notepad and never do anything.

Enter the following line into Notepad.  Replacing the <computername> with the relevant workstation name.

PSEXEC -i -d -s <computername> c:\\windows\\system32\\defrag.exe c:

Add as many lines as needed, using the unique computer name of each PC on your network.

Once you have completed your batch file, double click on it to run.  A command window will display the results of the task being run.  Showing if the remote command was successful or not.

Now what about this command and its parameters?  Well this is actually quite simple.  The -i means that the program will run interactively with the user, allowing them to close the task if needed.  The -d instructs PSEXEC to move onto the next command in the batch file and not to wait for the command to finish.  The -s tells PSEXEC to use the local SYSTEM account of the workstation, avoiding possible permission issues.

Some other things to be aware of;

  • Some Antivirus programs detect PSEXEC as a virus/worm, this is because some virus authors have either used PSEXEC or some of its code to remotely execute there viral programs on networked workstations.
  • Firewalls need to have appropriate access entries to allow PSEXEC to execute.  You can find out more by reading the notes on the sysinternals website.

Lastly, the author of this article accepts no responsibility for your use of these notes.

Similar Posts