I have a file transcript-test.ps1 with below contents
$log="TestLog{0:yyyyMMdd-HHmm}" -f (Get-Date) $logfile = 'C:\logs\'+$log+'.txt' Start-transcript -path $logfile -force Write-host "To test if this message gets logged" Stop-transcript
I try to run the script from lets say "box1" and the log file contains the below contents
********** Windows PowerShell Transcript Start Start time: 20110105114050 Username : domain\user Machine : BOX1 (Microsoft Windows NT 5.2.3790 Service Pack 2) ********** Transcript started, output file is C:\logs\TestLog20110105-1140.txt
To test if this message gets logged
********** Windows PowerShell Transcript End End time: 20110105114050
When I run the same script from another machine using below script I don't see any messages in the log file
Invoke-command {powershell.exe -ExecutionPolicy Unrestricted -NoProfile -File C:\in ll\transcript-test.ps1} -computername box1 -credential $credential get-credential
Contents of log file :
********** Windows PowerShell Transcript Start Start time: 20110105114201 Username : DOMAIN\user Machine : BOX1 (Microsoft Windows NT 5.2.3790 Service Pack 2)
********** Windows PowerShell Transcript End End time: 20110105114201
Is there anyway to log the messages from the script to log file when invoked remotely ?
Thanks! Sanjeev