gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:39:34 32 4
gpt4 key购买 nike

我创建了以下脚本(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)

但是在执行脚本后生成的日志文件中,我没有看到远程或本地的日志语句。这曾经适用于 Powershell 3.0,但最近我升级到 Powershell 4.0,但它停止工作。

有没有人遇到过类似的问题,或者知道从远程和本地命令捕获输出的任何其他方法?

谢谢,

高拉夫

最佳答案

这是 Microsoft 提供的用于解决此问题的修补程序:
https://support.microsoft.com/en-us/kb/3014136
也在此处讨论,在 Technet 中
https://social.technet.microsoft.com/Forums/windowsserver/en-US/cecc4f32-28c8-4bdc-be63-49ce3d396625/powershell-4-starttranscript-does-not-log-writehost?forum=winserverpowershell
从修补程序站点:

On a server that's running Windows Server 2012 R2, you encounter one or more of the following issues when you use PowerShell:

  • Issue 1

The Start-Transcript cmdlet does not capture write-host calls, as seen in the following script example:

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.

关于Powershell 4.0 Transcript 未捕获 Write-Host 语句的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29085362/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com