Powershell - 使用远程处理的Start-transcript问题

时间:2011-01-05 17:53:05

标签: powershell powershell-v2.0 powershell-remoting

我有一个带有以下内容的文件transcript-test.ps1

  

$ log =“TestLog {0:yyyyMMdd-HHmm}” - f   (Get-Date)$ logfile =   'C:\日志\' + $登录+ 'TXT'。   Start-transcript -path $ logfile -force   写主机“测试是否记录此消息”   停止转录

我尝试从说“box1”运行脚本,日志文件包含以下内容

  

** * ** * ** * 的* Windows PowerShell脚本开始   时间:20110105114050用户名:   domain \ user机器:BOX1   (Microsoft Windows NT 5.2.3790服务   包2)    * ** * ** * ** * 成绩单已启动,输出文件是   C:\ logs \ TestLog20110105-1140.txt

     

测试此消息是否已记录

     

** * ** * ** * 的* Windows PowerShell脚本结束时间:   20110105114050

     

当我使用下面的脚本从另一台机器运行相同的脚本时,我在日志文件中看不到任何消息

  

Invoke-command {powershell.exe   -ExecutionPolicy Unrestricted -NoProfile -File C:\ in ll \ transcript-test.ps1} -computername   box1 -credential $ credential get-credential

日志文件的内容:

  

** * ** * ** * 的* Windows PowerShell脚本开始   时间:20110105114201用户名:   DOMAIN \ user机器:BOX1   (Microsoft Windows NT 5.2.3790服务   包2)

     
     

** * ** * ** * 的* Windows PowerShell脚本结束时间:   20110105114201

     

是否有远程调用时将脚本中的消息记录到日志文件中?

谢谢! Sanjeev

2 个答案:

答案 0 :(得分:0)

Invoke-command将代码执行到一个作业中,就我所知道的没有控制台的线程而言,所以没有转录。对我来说,你得到的是绝对正常的。

答案 1 :(得分:0)

以下内容将捕获转录本中的本地和远程详细消息

$VerbosePreference = "continue"
Start-Transcript -path c:\temp\transcript.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
相关问题