When I run PsExec on a remote computer, I always fall short of what I want. What I would like ideally in most situations is a) a log on an admin server where each individual log has the name of each the remote computer it was generated from (e.g. COMPNAME1.log, COMPNAME2.log, etc.) or b) a log file on each remote computer with whatever name I specify.

When I try scenario (a), I use the following command.

%SystemDrive%\path\to\psexec.exe @listofcomputers.txt -u DOMAIN\username cmd /c echo TEST >> \\server.company.tld\share\%computername%.log

Problem is that it never works. All the computers just write to the log where %computername% is just the computer I execute PsExec from in my office. What I want are unique logs for each computer specific in the listofcomputers.txt that will correctly use the hostname from the remote environment variable without issue. Is that even possible? It does not seem to work for me. I tried this, and the syntax is clearly wrong.

%SystemDrive%\path\to\psexec.exe @listofcomputers.txt -u DOMAIN\username "cmd /c echo TEST >> \\server.company.tld\share\%computername%.log"

PsExec just fails saying the system file cannot be found (read: syntax fail).

As for scenario (b), it appears to be a variation of a similar problem. When I run a command like this, it does not work.

%SystemDrive%\path\to\psexec.exe @listofcomputers.txt -u DOMAIN\username "cmd /c echo %computername% >> \\server.company.tld\share\aggregated.log"

Is there something I do not understand about remote path and environment variables with PsExec on the cmd.exe console (I have not even tried the dreaded PowerShell yet). I know such things work in a batch file (cmd /c \\server.company.tld\share\runthis.bat), but is there a reason it will not work when executing commands as arguments? I always need this, and can never get it!

link|improve this question
No one have a clue? Might ask this at the SysInternals forum too and post back an answer. – alharaka Apr 12 '10 at 1:02
feedback

6 Answers

what are the real commands that your trying to psexec?

link|improve this answer
It does not really matter. At this point I was just trying to find some computers in an OU to make sure they are alive and kicking. The next step would be getting, say info from ipconfig. This was more of a theoretical question, but let's say for now I want: %SystemDrive%\path\to\psexec.exe @listofcomputers.txt -u DOMAIN\username ipconfig %computername% >> \\server.company.tld\share\%computername%.log" – alharaka Apr 9 '10 at 13:28
just saying in this case psexec is the wrong tool! wmi in specific wmic, would give you better output. – tony roth Apr 16 '10 at 4:12
Yea, completely wrong tool for the job. You want a scripted solution from VBScript or Powershell (or Perl, or Python, or JScript, or.....), basically anything that can interface with LDAP/AD and (maybe) WMI. Go hit up the Microsoft Technet Script Center. – gWaldo Sep 20 '10 at 19:35
feedback

You need to escape with the caret sign ^ , otherwise cmd tries to solve the variable. for example, to get the remote computer name

psexec \\pc cmd.exe /c echo ^%computername^%
link|improve this answer
feedback

Gents, I finally made it to work:

psexec \\server cmd.exe /c echo %%computername%%

(notice the double percent signs)

link|improve this answer
feedback

psexec \computer cmd.exe /c Echo %computername%

will do what you want

PS PSEXEC rocks! People who think batch script is dead don't know how to use it

link|improve this answer
feedback

Create a .cmd (or whatever) that does what you need, then *-c*opy over to the list of machines using psexec for execution.

link|improve this answer
feedback

Power Admin's PAExec (PsExec replacement) has optional command options to log what it is doing. Maybe that is what you're after?

link|improve this answer
feedback

Your Answer

 
or
required, but never shown