Solved

solution for scheduled defrag on pcs in the list and shutdown after defrag

Posted on 2009-07-08
4
344 Views
Last Modified: 2012-05-07
Currently I have three different script:

1. First script will send out the magic packet to wake pcs
2. Second script will run the defrag for all the pcs that are listed in the text file using psexec
    psexec @pc_list.txt -u administrator -p password -d -e defrag.exe c:
3. Finally using psshutdown from sysinteral to shut down pc listed int the text file.
    psshutdown -u administrator -p password -s -c @pc_list.txt

I am using windows scheduler to run the script at night.
I think the current script doing quite well and very simple to use. However when i think of improving the script, pcs should shut down right after defrag is finished.

Wondering if there is easy way to improve the script so the pcs shut down right after defrag is finish.

if i don't use psexec to do remotely following script should work but can't figure out how to use with psexec.

defrag c: -f
shutdown -s -t 10 -f -c "Shutdown after defrag"






0
Comment
Question by:monaye
4 Comments
 
LVL 23

Expert Comment

by:rhandels
ID: 24806321
Hey,

I don't believe you can.. For as far as i know it is impossible to shut down the PC after the defrag using a defrag command line.
The other issue is that when you actually trigger the reboot from the same batch file as you trigger the defrag, you need to do some sort of timeout within the bacth script that shuts down the PC. This isn;t your biggest issue, creating a timeout.. The problem is that you cannot tell how long the defrag is going ot take before it ends..

As far as i can see the batch execution you set up is a very good solution..
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 350 total points
ID: 24806349
The command below will defrag the remote machine and then shut down when it is finished.


psexec \\<computer> cmd /c defrag c: -f ^& shutdown -s -t 10 -f -c "Shutdown after defrag"

Open in new window

0
 
LVL 1

Author Comment

by:monaye
ID: 24809222
Thank you Shift-3,

It looks so simple after all.
All you are doing is psexec the cmd and passing the command?

It works perfect.

Do you happen to know how to output log to text file?
0
 
LVL 1

Expert Comment

by:Fritch84
ID: 25139787
Thanks very much for asking for this great little script command.  I'm just starting to use it now - working like a charm.

"Do you happen to know how to output log to text file?"

I'm sure if this is what you're after but if you add this to the end -' > c:\analysis.txt' - it will tell you the before analysis and then give you the defragmentation report.  The only problem with this is that the computer name is not listed next to the defrag report.  But at least it's a good confirmation that it's all working correctly.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now