need script to defrag client computers

How would I need to modify this script to defrag client computers every week on Sunday night?

I'm imaging I would save this as a .bat file and just run it with the computers.txt in the proper location?

for /f %a in (c:\computers.txt) do schtasks /create /s %a /ru system /sc weekly /st 01:00:00 /tn DefragAndOff /tr "defrag c: -w -v & chkntfs c: & SHUTDOWN.EXE -s -t 0 -f"


Thanks.
BryceRichertAsked:
Who is Participating?
 
merowingerConnect With a Mentor Commented:
do not change the path of the computers.txt file
either you use:

for /f %a in (c:\scripts\computers.txt) do schtasks /create /S %a /RU system /SC WEEKLY /D SUN /ST 00:00 /TN DefragAndOff /TR "defrag c: -w -v & chkntfs c: & SHUTDOWN.EXE -r -t 0"

or

for /f %a in (computers.txt) do schtasks /create /S %a /RU system /SC WEEKLY /D SUN /ST 00:00 /TN DefragAndOff /TR "defrag c: -w -v & chkntfs c: & SHUTDOWN.EXE -r -t 0"
0
 
merowingerCommented:
Save it as batch, include all Computers in th Computers.txt file.
When executing, the batch will create a scheduled task on the clients which executes defrag and a shutdown every sunday at the specific time.

for /f %a in (c:\computers.txt) do schtasks /create /S %a /RU system /SC WEEKLY /D SUN /ST 00:00 /TN DefragAndOff /TR "defrag c: -w -v & chkntfs c: & SHUTDOWN.EXE -s -t 0 -f"

0
 
BryceRichertAuthor Commented:
will this shut down the computer? I see the shutdown command there... what are the s,t and f for?

(Is there a reboot switch for the shutdown?)

Thanks.

Bryce.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
merowingerCommented:
S=shutdown
t=the time until shutdown
f=force shutdown
0
 
merowingerCommented:
reboot = r
0
 
BryceRichertAuthor Commented:
so would it be shutdown.exe -r  for the reboot?
0
 
merowingerCommented:
yes exactly.
Run shutdown /? for all switches
0
 
BryceRichertAuthor Commented:
if I put that bat file on the root of the c drive, I just go to a run and cmd prompt, navigate cd.. to the C: and type in filename.bat, and then it runs?

or do I put it in the system32 folder and jut type in filename at the run command, or is that only for exe files?
0
 
BryceRichertAuthor Commented:
when I run this:

for /f %a in (c:\scripts\computers.txt) do schtasks /create /S %a /RU system /SC WEEKLY /D SUN /ST 00:00 /TN DefragAndOff /TR "defrag c: -w -v & chkntfs c: & SHUTDOWN.EXE -r

A black box just flashes up on the screen for .1 seconds and dissappears.

I've put both this batch file and a file called "computers.txt" inside a folder called "scripts" on root of the c drive.


She I be seeing anything running or is it really that quick? Should I be able to go to the Control Pannel:Scheduled Tasks on the three test machines that are in the computers.txt file and see a defrag scheduled task show?

Thanks for your help on this.

Bryce.
0
 
merowingerCommented:
try to run the batch file with administrative permissons. for me it worked as i started an elevated dos prompt
0
 
BryceRichertAuthor Commented:
I'm using xp. I don't see a way to elevate it. I'm admin on my computer.

When I run the bat from it's folder (after navigating to the folder within a CMD window), the error says "do was unexpected at this time"

Bryce.
0
 
BryceRichertAuthor Commented:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\brycer>cd..

C:\Documents and Settings>cd..

C:\>scripts
'scripts' is not recognized as an internal or external command,
operable program or batch file.

C:\>cd scripts

C:\scripts>defrag-new-restart.bat
do was unexpected at this time.

C:\scripts>for /f \scripts\computers.txt) do schtasks /create /S 00 /TN DefragAndOff /TR "defrag c:
-w -v & chkntfs c: & SHUTDOWN.EXE -r
C:\scripts>
0
 
merowingerCommented:
if you are already in C:\scripts you don't need to define the path on the file
0
 
BryceRichertAuthor Commented:
OK, I changed the computers.txt location to just 'computers.txt'.

The bat file still just shows a black screen very quickly when I double click on the .bat file... shouldn't I be seeing it run?

also, if it's succesfuly, shouldn't I see a new scheduled task under Control Panel - Scheduled Tasks?
0
 
merowingerCommented:
yes you should.
Could you copy the command and execute it directly in a dos prompt windows. Then you should see what's going wrong
0
 
BryceRichertAuthor Commented:
It says "no was unexpected at this time".
0
 
merowingerCommented:
there was a error in syntax. Try this one:

for /f %a in (c:\scripts\computers.txt) do schtasks /create /S %a /RU system /SC WEEKLY /D SUN /ST 00:00 /TN DefragAndOff /TR "defrag c: -w -v & chkntfs c: & SHUTDOWN.EXE -r -t 0"
0
 
BryceRichertAuthor Commented:

C:\scripts>defragnew.bat
do was unexpected at this time.

C:\scripts>for /f \scripts\computers.txt) do schtasks /create /S 00 /TN DefragAndOff /TR "defrag c:
-w -v & chkntfs c: & SHUTDOWN.EXE -r -t 0"
C:\scripts>
0
 
BryceRichertAuthor Commented:
The above is what it said again.

Bryce.
0
 
BryceRichertAuthor Commented:
OK, I'll try this this evening. Thanks!
0
All Courses

From novice to tech pro — start learning today.