Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script: Mass Windows defragger

Performance

Script: Mass Windows defragger

by  hgate73  Posted    (Edited  )
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%
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top