2

I need to log everything printed to stdout to a file. Start-Transcript/Stop-Transcript works great and does exactly this, but only for the local PowerShell sessions. The problem is that Transcripts are not supported when executing PowerShell scripts in a remote session (using Enter-PSSession cmd).

Is there another (preferably simple) way to redirect all output to a file, even if the .ps1 script is executed in a remote session?
I'd prefer not to have to add >> or Tee or out-file etc. to every line in the script that has output.

I also do not want to Start-Transcript before entering the remote session. I'm remoting to many destinations in a loop and I need each remote session's stdout logged to a separate file (local to the endpoint), not all bundled into a single file.

bradvido
  • 2,743
  • 7
  • 32
  • 49
  • 1
    This should help you out: http://stackoverflow.com/questions/16178319/powershell-save-stdout-and-display-stdout – websch01ar Jan 17 '14 at 18:01

1 Answers1

0

I suggest using the Start-Transcript before entering the session, and using the -Path option of that cmdlet to point to a separate file for each session. Perhaps something like

Start-Transcript -Path C:\Logs\$MachineName-$($(Get-Date).ToString("yyyyMMddhhmm")).log

Or something similar. My personal preference is a date-time appendage for historical purposes.

MDMoore313
  • 3,233
  • 1
  • 23
  • 38