简体   繁体   English

Powershell 4.0 Transcript不捕获Write-Host语句的输出

[英]Powershell 4.0 Transcript is not capturing output of Write-Host statements

I have created following script(test.ps1) and I am executing it from command line as "powershell .\\test.ps1" 我创建了以下脚本(test.ps1),我从命令行执行它作为“powershell。\\ test.ps1”

Write-Host(Start-Transcript -Path "D:\logs.txt")
$remoteScript = {
    Write-Host "Remote Log"
}
Invoke-Command -ConnectionUri $uri -Credential $creds -ScriptBlock $remoteScript
Write-Host "Local Log"
Write-Host(Stop-Transcript)

However in the log file generated after executing script, I do not see the log statement either remote or local. 但是在执行脚本后生成的日志文件中,我没有看到远程或本地的日志语句。 This used to work with Powershell 3.0 but recently I upgraded to Powershell 4.0 and it stopped working. 这曾经与Powershell 3.0一起使用,但最近我升级到Powershell 4.0并且它停止了工作。

Has anyone faced similar issue or is aware of any other way to capture output from remote and local commands? 有没有人遇到类似的问题或者是否知道从远程和本地命令捕获输出的任何其他方法?

Thanks, 谢谢,

Gaurav 拉夫

Here is a hotfix from Microsoft to resolve this issue: 以下是Microsoft解决此问题的修补程序:

https://support.microsoft.com/en-us/kb/3014136 https://support.microsoft.com/en-us/kb/3014136

It is also discussed here, in Technet 这也在Technet中讨论

https://social.technet.microsoft.com/Forums/windowsserver/en-US/cecc4f32-28c8-4bdc-be63-49ce3d396625/powershell-4-starttranscript-does-not-log-writehost?forum=winserverpowershell https://social.technet.microsoft.com/Forums/windowsserver/en-US/cecc4f32-28c8-4bdc-be63-49ce3d396625/powershell-4-starttranscript-does-not-log-writehost?forum=winserverpowershell

From the Hotfix site: 从修补程序站点:

On a server that's running Windows Server 2012 R2, you encounter one or more of the following issues when you use PowerShell: 在运行Windows Server 2012 R2的服务器上,使用PowerShell时会遇到以下一个或多个问题:

  • Issue 1 问题1

The Start-Transcript cmdlet does not capture write-host calls, as seen in the following script example: Start-Transcript cmdlet不捕获写主机调用,如以下脚本示例所示:

Start-Transcript -path $env:TEMP\\transcript.txt
Write-Host Hello World
Stop-Transcript

Get-Content $env:TEMP\\transcript.txt
In this case, "Hello World" does not appear in the transcript.txt file as expected. 在这种情况下,“Hello World”不会按预期出现在transcript.txt文件中。

Write-Output替换Write-Host在2012 R2上为我做了诀窍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM