how to use psexec to defrag all my computers

R

Rich

I have a text file named computers.txt that lists all my workstations, one
per line. For the life of me I can't figure out how to use this with psexec
logging in as the local admin with a -u administrator to defrag all my
workstations in this file. anyone have a working command line with the -u
and -p in it they could share?
 
J

John John - MVP

If you run it from a local administrator account it should have
administrative privileges on the remote machine. You can also run it
under the all powerful System account if you have to. Are all the
remote machines using the same Administrator name and password? If yes
run it from a local Administrator account with the same credentials, but
if you are logged on as an administrator I don't think that should be
necessary.

John
 
S

Shenan Stanley

Rich said:
I have a text file named computers.txt that lists all my
workstations, one per line. For the life of me I can't figure out
how to use this with psexec logging in as the local admin with a -u
administrator to defrag all my workstations in this file. anyone
have a working command line with the -u and -p in it they could
share?

If I were to do that...

Copy a *.cmd (give it a valid name) to each of the machines - whatever
location you desire. The contents of that *.cmd file could be something
like:

defrag %systemdrive% -f > \\server\share\%computername%-defrag.txt

Then start that *.cmd file using PSEXEC on each machine and wait for the
\\server\share to populate with the text files. It should tell you what
their status was when starting and what their status was at the end.

The batch/cmd script to do both of those things (assuming you created the
file mentioned above and called it defrag.cmd and the text file you
mentioned was called pclist.txt and everything - including psexec - was in
the same directory when you started) would look like this:

for /f %%u in (pclist.txt) do (
copy /y .\defrag.cmd \\%%u\c$\temp
start psexec \\%%u -u "USERwRIGHTS" -p "%1" c:\temp\defrag.cmd
)

Let's say it was called "RemDefrag.cmd", you would start it with a command
line:

RemDefrag USERwRIGHTS-Password

Then it would parse through your pclist.txt, copy the defrag.cmd file to the
temp directory on each machine (assuming it existed) and then it would use
PSEXEC to start the defrag.cmd on each computer as "USERwRIGHTS" using the
password you provided. It would also write a text file unique to each
computername to a server location for you to peruse at your leisure
now/later.

In any case - there's a simple/built-in way.
 
R

Rich

Yeah, all my machines have the same administrator username and password, i
just think maybe I'm doing something wrong. below is what i was trying to
do. I get a bunch of cmd windows to pop up, then they all close fairly
quickly, i think saying the file or path can't be found. it disappears too
quickly to see for sure.

set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Wscript.Shell")
set objFile = objFSO.OpenTextFile("C:\documents and
settings\Rich\desktop\computers.txt")

Do while not objFile.AtEndOfStream
currentpc = objFile.Readline
objShell.Run "c:\tools\psexec -s \\" &currentpc &" -u administrator -p
password " &Chr(34) & "c:\windows\system32\defrag.exe c: -f" &Chr(34)
Loop
 
J

John John - MVP

Well, I'm not sure about the script but from the Command Prompt this
simple command gets it going on my remotes:

psexec \\ComputerName defrag.exe c: -f

That is all that I need to have it run, no need for the -s - u or -p
switches. With the FOR /f command as suggested by Shenan you should be
able to get it going.

John
 
N

Nicholas Li [MSFT]

Hi,

Thank you for posting.

I am sorry to say that PsExec do not come with support. This is stated in
the EULA (END-USER LICENSE AGREEMENT) that has to be agreed to in order to
complete the install and use them. "SUPPORT SERVICES. Because this
software is "as is," we may not provide support services for it."

As such, they are provided "AS IS" and we try to assist here in the
newsgroups with them as a "best effort" to help anyone experiencing issues
with them.

If you need assistance on PsExec, I would like to suggest that you post the
question to Sysinternals Forum. Meanwhile, we hope others who read the
public newsgroups regularly who will either share their knowledge.

Sysinternals Forum
http://forum.sysinternals.com/

I hope the problem will be resolved soon. Thank you for your understanding.

Best regards,

Nicholas Li
Microsoft Online Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top