×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Performance

Script: Mass Windows defragger by hgate73
Posted: 17 Apr 10

This script reads through a "names.txt" file with a FOR loop and executes that command for each PC. It defrags ALL computers listed in that file.

Without further ado!

batch file

CODE

:: Purpose:         Defrags all computers listed in the names file
:: Requirements:    1. Run this script with network admin privileges
::                  2. psexec.exe from Microsoft must be in any of these locations:
::                      a) the directory you run this script from
::                      b) in the PATH variable
::                      c) c:\windows\system32\    (preferred)
::                  3. Put the names of your computers, one per line, in a file called "names.txt" in the same directory as this script
::
:: Version:         1.1 Improved script by adding functionality to read a list of computer names from a text file
::                      instead of hard-coded in the script. Uses a FOR loop to iterate through the file.
:: History:         1.0 Initial write

:: Prep
@echo off
title Mass Defragger
set VERSION=1.1
set NAMES_FILE=names.txt
set TIMEOUT=5
cls

:: User notice
color 0c
echo.
echo  *********************************************************
echo  *                                                       *
echo  *                   MASS DEFRAGMENTER                   *
echo  * ----------------------------------------------------- *
echo  *                                                       *
echo  * RULES for a safe and happy mass defragging:           *
echo  *                                                       *
echo  * 1. Run this script with NETWORK ADMIN rights.         *
echo  * 2. Edit this script BEFORE RUNNING IT to put in your  *
echo  *    own system names.                                  *
echo  * 3. Run this script from the desktop, NOT a network    *
echo  *    path.                                              *
echo  * 4. "psexec.exe" from Microsoft must be in either:     *
echo  *     a. the same directory as this script              *
echo  *     b. C:\WINDOWS\system32\                           *
echo  *     c: the system PATH variable                       *
echo  * 5. A file named "names.txt" must be in             *
echo  *     the same directory of this script. List the names *
echo  *     of the computers you want defragged, one name per *
echo  *     line.                                             *
echo  *                                                       *
echo  *********************************************************
echo.
echo.
pause
color 07
cls

:: HIROSHIMA!
title Mass Defragging -- Timeout %TIMEOUT% seconds
cls
echo.
echo Performing mass defragmentation, with a %TIMEOUT% second connection timeout.
echo Please wait...
echo.

FOR /F %%i in (%NAMES_FILE%) do psexec -a 0 -belownormal -n %TIMEOUT% -d \\%%i defrag c: -f

title Mass Defragger --  Complete
echo.
echo Mass Defragger -- Complete
echo.
pause
title %USERNAME%

Back to Microsoft: Windows FAQ Index
Back to Microsoft: Windows Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close