I'm trying to run multiple commands remotely using psexec.
I launch psexec from a local computer then specify the remote computer to connect. I want to store the output of the remote command on my local pc that initiated the psexec command.
If use ">" or ">>" the file gets created on the remote pc, not on my local pc.
Here is the code that I use:
cmd /c "c:\windows\system32\psexec.exe" \\192.168.0.2 -accepteula -u test -p test -s cmd /k (date /t) ^& (time /t) ^& (hostname) ^& (wmic csproduct get name, identifyingnumber) ^& (net statistics workstation) ^& (wmic LOGICALDISK LIST BRIEF) ^& (echo.) ^& (net use) ^& (tasklist)'+' ^& (echo.) ^& (echo. LISTARE CONTINUT FISIER HOSTS:) ^& (type c:\windows\system32\drivers\etc\hosts)
What am I doing wrong?
That is how PSExec works, on the other computer. WMIC can do what you want all by itself.
wmic /node:127.0.0.1 process get /format:list
or
wmic /node:@C:\folder\computerlist.txt process get /format:list
computerlist.txt looks like this
127.0.0.1
MyComputerName
168.0.0.1
so you can mix 'n match names or ip addresses.
or
wmic /node:127.0.0.1 /output:C:\folder\output.txt process get /format:list
Although wmic does do redirection. Use Append
instead of output
to append.
See wmic /?
, wmic /output /?
, and wmic /format /?
.
Also wmic can run programs invisible on other computers.
wmic /node:127.0.0.1 process call create notepad.exe
Because 127.0.0.1 is a local address you'll see notepad but won't see it on a remote computer. See wmic process call create /?