Question Locked

Using Group Policy to defrag XP PC's- Scrpits, Batch files??

0 helpful
14 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need a script or batch file I can push out using Group Policy. Any ideas. Please help Thanks

14 replies

by dumphrey

and the problem I keep bumping into is permissions. Defragging requres at least poweruser and I refuse to give peeps that permission unless required.

a simple batch file with
defrag c:
will do the job if the logged in user has permissions, or you can use a batch file on the local machine to contact the remote machine using the sysinternal psexec command, but this requires a deal of time and a single admin password on each machine. If I could find a way to make the command start the crocess and then move on, I would be happy, as it is, it waits for the spawned process to finish befor starting on the next itteration.
EDIT:
I just reread the psexec command settings
psexec \\MachineName -s -d defrag c:
will start a defrag session on the remote machine, running it under the system account, and then return control of the shell to the batch/user. I need to test if it leaves the spawned process running on the remote machine.

EDIT2:
for /f %%a in (c:\list.txt) do psexec -s -d \\%%a defrag c: && shutdown -s -f
in a batch file will read each successive entry in list.txt, spawn a terminal session, run defrag c: and then shutdown the box. In theory. I have only partialy tested this.
List.txt should be a list of machine names or ip address you want to defrag and shutdown.

by jshoe85

I had a script in the past that worked using GP. I cannot find it though.

by dumphrey

and it has a code snippit that works. You can push out scripts that run as system accounts through GP. This is almost as easy, and can be scheduled to run on Friday nights late. I would be interested to find a GPO to defrag machines.

This script will not work on 2000, just XP and above.

by dumphrey

for /f %%a in (c:\list.txt) do psexec -s -d \\%%a defrag c: && shutdown -s -f

Save this as a .bat file. Download psexec from sysinternals
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
Create a directory on your desktop, put the extracted psexec.exe and you .bat file in this directory. Create a list of machine names you want to defrag, an AD dsquery output or manual list creation. Name this file list.txt. Double click .bat file or add it to scheduled tasks for later in evening. Let me double check my dsquery command to get machine names. I will edit this and add the command.

by jshoe85

I appreciate it but I was looking for the script I had that I can just link to a GPO...

by jshoe85

I did have one that worked when a user shut down. That's what I'm looking for, just something to make a gpo that runs the logoff scrpit and rund defrag at shutdown.

by dumphrey

I have found this to be more flexable though, as you can only set GPO script for logon or logoff. I can run this at midnight on saturday one one group and 2 am on friday on another etc..
I do understand why you want a gpo script for management. And I am looking for one as well, but so far all I can find is a gpo plug-in for Diskeeper, but it requires Diskeeper to be installed on each workstation.

by dumphrey

of supplying appropriate permissions to run the script as a GPO. =\ Hence my workaround. I will keep digging this after noon and see if I can find any VB to do the trick.

by w2ktechman

Before pushing this, it is a good idea to push out a backup service that will force backups.
While not common, it is likely that an HDD with issues will be unrecoverable after a defrag.
I have seen this happen more than once. I caused it once. Defrag, while usually recommended should not be performed on a drive that is showing signs of faltering. Doing it may just destroy all of the data.

by dumphrey

My actual script I use has a chkdsk performed before it defrags, and only does the defrag if chkdsk exits with no problems found.
Lucky for me, 90% of our work resides and takes place on servers. We would be a top canidate for thin clients in all reality, so I defrag only about every 3 months on the workstations.

" Defrag, while usually recommended should not be performed on a drive that is showing signs of faltering. Doing it may just destroy all of the data"

I crashed an old workstation because I defraged in stead of chkdsked first. I have a feeling chkdsk would no thave helped either. A low level format got it back in service for about another year, in a non-trusted and non-important role.

This discussion is closed to new replies.