Powershell 4: Start-Transcript does not log Write-Host

Hi, 

After creating an instance of the latest Windows Server 2012 R2 image on Windows Azure, we see a strange issue with Powershell transcripts: Write-Host is not transcribed. However, "foobar" | Out-Host IS transcribed! Very strange. However, both Write-Warning, and any errors (exceptions, or write-error) does give output.

Anyone else seen this issue? Is this expected behavior or a bug?

Thanks a lot in advance! :-)

Sincerely,

Hallgeir

Here's my powershell version info:

PS C:\> $psversiontable

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.34014
BuildVersion                   6.3.9600.17400
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

Example:

**********************
Windows PowerShell transcript start
Start time: 20150114143638
Username: xxx\xxx
RunAs User: xxx\xxx
Machine: xxx (Microsoft Windows NT 6.3.9600.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 2160
**********************
Transcript started, output file is C:\foobar.txt

PS C:\> Write-Host "This is a test"

            CurrentMatchIndex              ReplacementIndex             ReplacementLength CompletionMatches
            -----------------              ----------------             ----------------- -----------------
                           -1                             0                            12 {System.Management.Automat...



PS C:\> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20150114143658
**********************

Here's how it looks with piping to Out-Host:

**********************
Windows PowerShell transcript start
Start time: 20150114143755
Username: xxx\xxx
RunAs User: xxx\xxx
Machine: xxx (Microsoft Windows NT 6.3.9600.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 2160
**********************
Transcript started, output file is C:\foobar.txt

            CurrentMatchIndex              ReplacementIndex             ReplacementLength CompletionMatches
            -----------------              ----------------             ----------------- -----------------
                           -1                            19                             8 {System.Management.Automat...



PS C:\> "This is a test" | Out-Host
This is a test

            CurrentMatchIndex              ReplacementIndex             ReplacementLength CompletionMatches
            -----------------              ----------------             ----------------- -----------------
                           -1                             0                             9 {System.Management.Automat...



PS C:\> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20150114143809
**********************


  • Edited by Hallgeirl Wednesday, January 14, 2015 2:42 PM
January 14th, 2015 2:42pm

Hi,

This is a bug, and we're working on getting it fixed in an upcoming update.

Brent

Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2015 1:58am

I've just run into this on one of my 2012 R2 servers.  It's been working fine for months, but all of a sudden I've started seeing this behaviour.

Does anyone have a workaround until this is fixed?  I'd rather not have to change all my scripts.

Thanks

* should be noted I'm using on prem, not azure

April 13th, 2015 8:33am

In my testing I discovered that this bug only appears after installing KB3000850, so that might be why it just showed up for you.  It has now been almost 6 months and none of the latest updates resolve the issue.

I had used workaround code for this in the past because early versions of PowerShell did not transcribe Write-Host, however they added the functionality sometime in version 2.0.  At that point I ripped out my workaround and everything had been working fine until recently, and I traced it to KB3000850.

I get that Write-Output is a good practice, but I'm writing scripts for customers that don't really know what's going on and spend a lot of time making the output look good.  Write-Output doesn't support colours out of the box, and I don't need any of the output I'm displaying passed to other scripts.  It's informational.  Unfortunately it's also really useful for debugging what when wrong and when, except when it doesn't show up in the transcript!

Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2015 4:20pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics