0

I Have a piece of code that I use to deploy software to a list of computers via their host-names.

I need retrospective logging for any failures where PSEXEC failed for whatever reason.

I have looked hard into this and have got there to a degree, but only so far that the CMD window doesn't out put what it's doing, everything is just going to the logfile, which gets tedious opening and closing all the time to see what's happening or not. I need real-time output of everything in the CMD window as it runs and also a log file to look at after it's run.

Here is a sample of the code :-

cls
echo.
Echo (PS) Deploying Installer.exe...
echo.
for /f "usebackq tokens=*" %%A in (hostnames.txt) do (
echo %%A Receiving files, Wait...
robocopy ..\ "\\%%A\c$\Windows\Temp" Installer.exe /njh /njs /ndl /nc /ns /R:0
Plugins\Ps_Files\psexec.exe \\%%A -accepteula -d "\\%%A\c$\Windows\Temp\Installer.exe" >> Logs\Installer.log 2>&1
) 

I have another version of PSEXEC called PAEXEC which has a built in switch (-lo somefile.txt) for logging, so when that works it's great - everything catered for, but doesn't work as well as PSEXEC, which is lacking in a dedicated logging switch.

I have also tried to add & type Logs\Installer.log to the end of the PSEXEC command but that ends up in chaotic duplication.

Any ideas on how to make the PSEXEC command included make a log file of what is out putted to the CMD window.

Normally you get installer.exe started with process id 3456 error code 0

'or'

psexec service could not start error code 245

I would like this in the cmd window & a log file

at present I can only see these things in the log-file using the code supplied.

Many thanks.

Tika9o9
  • 405
  • 4
  • 22
  • 2
    You need a [Tee](https://en.wikipedia.org/wiki/Tee_(command)) command. There's one built-in to Powershell, or you can probably find one online. – jwdonahue Aug 17 '19 at 18:24
  • Finally, been looking into this for ages. Thankyou! What I got to work was the following – Tika9o9 Aug 18 '19 at 08:26
  • 2>&1 | pathto\tee -a Logs\Test.log (needed -a switch to prevent overwrites) – Tika9o9 Aug 18 '19 at 08:27

0 Answers0