Logging PSexec results

My script however some machines are not going to connect I am sure. How do I pass the results to a log file so that I can review what it missed?

@ECHO ON

set controlfile=serverlist.txt


FOR /F %%L IN (%controlfile%%) DO (
  SET "line=%%L"
  psexec \\%%L net user somesuer somepassword /add && net localgroup administrators "someuser" /add
)

Open in new window

LVL 2
stlhostAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed KhawajaManager - Infrastructure:  Information TechnologyCommented:
@ECHO ON

set controlfile=serverlist.txt


FOR /F %%L IN (%controlfile%%) DO (
  SET "line=%%L"
echo %%L >> logfilename.txt
  psexec \\%%L net user somesuer somepassword /add && net localgroup administrators "someuser" /add >> logfilename.txt
)
0
stlhostAuthor Commented:
Tried this method I even tried >> \\servershare\log.txt and it didnt work. Txt file shows The command completed successfully. That is all it says
0
NVITEnd-user supportCommented:
Try this:
@ECHO ON
set controlfile=serverlist.txt
FOR /F %%L IN (%controlfile%) DO (
  SET "line=%%L"
  psexec \\%%L net user somesuer somepassword /add 2>> logfilename.txt && net localgroup administrators "someuser" /add >> logfilename.txt
)

Open in new window

0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
1. There is double percent where it shouldn't in the FOR.
2, && is a command separator in a batch, so the second command is executed locally instead of remote.
3. Using PsExec with a more complex command can get tricky, because of need of proper escaping, and some bugs and issues with both cmd.exe and PsExec.
@ECHO ON

set controlfile=serverlist.txt

FOR /F %%L IN (%controlfile%) DO (
  SET "line=%%L"
  psexec \\%%L cmd /c "net user somesuer somepassword /add && net localgroup administrators ^"someuser^" /add"
) >> logfile.txt 2>&1

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stlhostAuthor Commented:
Perfect thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.