Solved

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

Posted on 2009-07-08
4
356 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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