Solved

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

Posted on 2009-07-08
4
357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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