Powershell 4.0 Transcript does not capture the output of Write-Host statements

I created the following script (test.ps1) and I execute it from the command line as "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 the script was executed, I do not see the log statement either remotely or locally. This was used to work with Powershell 3.0, but I recently upgraded to Powershell 4.0 and stopped working.

Has anyone encountered a similar problem, or knows of any other way to capture output from remote and local commands?

Thanks,

Gaurav

+5
source share
2 answers

Here is a fix from Microsoft to solve this problem:

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

It is also discussed here at 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 site corrections:

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

  • Problem 1

The Start-Transcript cmdlet does not capture write-based calls, as shown 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.

+2
source

Replacing Write-Host with Write-Output did the trick for me in 2012 R2.

+1
source

Source: https://habr.com/ru/post/1215475/


All Articles