transcript using remoting

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 : domainuser Machine : BOX1 (Microsoft Windows NT 5.2.3790 Service Pack 2) ********** Transcript started, output file is C:logsTestLog20110105-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 lltranscript-test.ps1} -computername box1 -credential $credential get-credential

Contents of log file :

********** Windows PowerShell Transcript Start Start time: 20110105114201 Username : DOMAINuser 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


Invoke-command execute your code into a job, which is as far as I understant a thread with no console, so no transcription. For me what you got is absolutly normal.


以下内容将在抄本中捕获您的本地和远程详细消息

$VerbosePreference = "continue"
Start-Transcript -path c:temptranscript.txt 

Write-Verbose "here 1"

$job = Invoke-Command cbwfdev01 -ScriptBlock {

    $ErrorActionPreference = "Stop";
    $VerbosePreference = "continue";

    Write-Verbose "there 1";
    Write-Verbose "there 2";
    Write-Verbose "there 3";

} -AsJob 

Wait-Job $job | Out-Null

$VerboseMessages = $job.ChildJobs[0].verbose.readall()

ForEach ($oneMessage In $VerboseMessages) {Write-Verbose $oneMessage}

Write-Verbose "here 2"

Stop-Transcript
链接地址: http://www.djcxy.com/p/61082.html

上一篇: 带有参数的Powershell GPO启动脚本

下一篇: 成绩单使用远程处理