PC Review


Reply
Thread Tools Rate Thread

CMD defrag help

 
 
aaron
Guest
Posts: n/a
 
      15th Sep 2005
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,
--
aaron
A+,NET+,MCSE 2K/2K3,CNA,CCNA


 
Reply With Quote
 
 
 
 
Jerold Schulman
Guest
Posts: n/a
 
      16th Sep 2005
On Thu, 15 Sep 2005 14:13:14 -0500, "aaron" <(E-Mail Removed)> wrote:

>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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP home - NTFS files - cannot defrag - chkdsk and defrag =?Utf-8?B?Um9zaWU=?= Windows XP Performance 1 23rd Nov 2007 04:24 AM
Too many fragments remain after defrag and defrag takes too long =?Utf-8?B?Sm95Y2U=?= Windows XP Help 25 19th Oct 2006 11:38 PM
Defrag help !! defrag runs fine but doesnt defrag the drive bob Microsoft Windows 2000 3 14th Mar 2005 08:48 PM
Defrag and CHKDSK, Defrag Exchange 2000 Store smitto Microsoft Windows 2000 Advanced Server 0 10th Jul 2003 04:50 PM
Windows (XP Home) Defrag vs. Command Line Defrag Indigo Windows XP Performance 0 3rd Jul 2003 11:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 PM.