CMD defrag help

A

aaron

I am trying to write a batch file that will run the defrag -a -v command for
a list of machines so I can determine which machines need defragged. I can't
seem to get it to go past one line. How do I make the file continue on to
the next line? I am doing this remote through ps tools psexec.
I would like to capture the ouput of the cmd window to a text file for easy
search and logging. All machines are Server 2003.

Ex: of what I would like for analysis

psexec \\server1 defrag -a -v c:
psexec \\server1 defrag -a -v d:
psexec \\server2 defrage -a -v c:
psexec \\server3 defrag -a -v c:
etc..........

Then
psexec \\server1 defrag c:
psexec \\server1 defrag d:
psexec \\server2 defrage c:
psexec \\server3 defrag c:
etc..........
TIA,
 
J

Jerold Schulman

I am trying to write a batch file that will run the defrag -a -v command for
a list of machines so I can determine which machines need defragged. I can't
seem to get it to go past one line. How do I make the file continue on to
the next line? I am doing this remote through ps tools psexec.
I would like to capture the ouput of the cmd window to a text file for easy
search and logging. All machines are Server 2003.

Ex: of what I would like for analysis

psexec \\server1 defrag -a -v c:
psexec \\server1 defrag -a -v d:
psexec \\server2 defrage -a -v c:
psexec \\server3 defrag -a -v c:
etc..........

Then
psexec \\server1 defrag c:
psexec \\server1 defrag d:
psexec \\server2 defrage c:
psexec \\server3 defrag c:
etc..........
TIA,


Create the follow dfrg.bat file in your path.

@echo Off
if {%2}=={} @echo Syntax dfrg Server Drive&goto :EOF
setlocal
set comp=%1
set drv=%2
set OK=Y
for /f "Tokens=*" %%a in ('psexec %comp% defrag -a -v %drv%^|find "You do not need to defragment this volume."') do (
set OK=N
)
if "%OK%" EQU "Y" psexec %comp% defrag %drv%
endlocal

Then

call dfrg \\server1 c:
call dfrg \\server1 d:
call dfrg \\server2 C:
call dfrg \\server3 C:
etc.


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top