Gau*_*rav 5 powershell powershell-ise powershell-remoting powershell-3.0 powershell-4.0
我创建了以下脚本(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)
Run Code Online (Sandbox Code Playgroud)
但是在执行脚本后生成的日志文件中,我没有看到远程或本地的日志语句.这曾经与Powershell 3.0一起使用,但最近我升级到Powershell 4.0并且它停止工作.
有没有人遇到类似的问题或者是否知道从远程和本地命令捕获输出的任何其他方法?
谢谢,
拉夫
以下是 Microsoft 提供的用于解决此问题的修补程序:
https://support.microsoft.com/en-us/kb/3014136
Technet 中也对此进行了讨论
来自修补程序站点:
在运行 Windows Server 2012 R2 的服务器上,使用 PowerShell 时会遇到以下一个或多个问题:
- 第1期
Start-Transcript cmdlet 不会捕获写入主机调用,如以下脚本示例所示:
Start-Transcript -path $env:TEMP\transcript.txt
Write-Host Hello World
Stop-Transcript
Get-Content $env:TEMP\transcript.txt
在这种情况下,“Hello World”不会按预期出现在transcript.txt 文件中。
| 归档时间: |
|
| 查看次数: |
4340 次 |
| 最近记录: |