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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
merowingerCommented:
S=shutdown
t=the time until shutdown
f=force shutdown
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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
merowingerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BryceRichertAuthor Commented:
OK, I'll try this this evening. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.