Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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