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 5:42pm

This is how PowerShell is designed to work.  Outpu is only visible in the console.

Free Windows Admin Tool Kit Click here and download it now
January 14th, 2015 5:55pm

Seems to work just fine for me:

**********************
Windows PowerShell transcript start
Start time: 20150114095742
Username  : me 
Machine	  : PC (Microsoft Windows NT 6.3.9600.0) 
**********************
Transcript started, output file is ...\PowerShell_transcript.20150114095742.txt
PS C:\> Write-Host 'TEST'
TEST
PS C:\> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20150114095754
**********************

January 14th, 2015 6:00pm

Not me:

**********************
Windows PowerShell transcript start
Start time: 20150114095333
Username: a
RunAs User: a
Machine: T (Microsoft Windows NT 6.3.9600.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 700
**********************
Transcript started, output file is C:\Users\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.20150114095333.txt

PS C:\scripts> write-host testing

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



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

Free Windows Admin Tool Kit Click here and download it now
January 14th, 2015 6:06pm

It's working fine for me as well in the previous version of the image Azure image, which used an older build of Powershell (6.3.9600.16394). With the new image however, there's no such luck :(
January 14th, 2015 6:20pm

I thought the whole purpose of transcript was to log everything that's going on? And it DID work previously :)
Free Windows Admin Tool Kit Click here and download it now
January 14th, 2015 6:21pm

It's working fine for me as well in the previous version of the image Azure image, which used an older build of Powershell (6.3.9600.16394). With the new image however, there's no such luck :(
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.17090
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

I am on a slightly older build than you are, that most likely accounts for the difference.

Still though, this could be a good excuse to get away from Write-Host. I've made it a habit to use Write-Output everywhere instead of Write-Host, due to things like this:

http://www.jsnover.com/blog/2013/12/07/write-host-considered-harmful/

January 14th, 2015 6:28pm

Thanks Mike.

Write-Output works perfectly; we'll use this instead.

Thanks everyone for your input; no more write-host for me :-)

Free Windows Admin Tool Kit Click here and download it now
January 14th, 2015 6:46pm

Cheers, you're welcome.
January 14th, 2015 6:47pm

Hi,

Write-Ouput works and we can set background and foreground colors with $host.UI.RawUI members but what about the nonewline parameter on write-host command ?

Free Windows Admin Tool Kit Click here and download it now
January 16th, 2015 12:16pm

Hi,

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

Brent

January 23rd, 2015 1:58am

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 4:58am

Thanks for the update Brent.
January 23rd, 2015 6:20am

Any indication of when this update is expected to be made available to the public?
Free Windows Admin Tool Kit Click here and download it now
February 3rd, 2015 11:13am

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 4:34am

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

Free Windows Admin Tool Kit Click here and download it now
April 13th, 2015 8:33am

Hi CheeseBiscuits,

i'm still waiting for an answer from MSFT as well, but they no longer seem to be monitoring this thread, probably because it is marked as answered.

The only workaround I could think of currently is to create a proxy/replace function for Write-Host that outputs the string using "String" | Out-Host. e.g.:

Function Write-Host ($message,$nonewline,$backgroundcolor,$foregroundcolor) {$Message | Out-Host}

I've started a new thread to see if we can get it fixed by MSFT:

https://social.technet.microsoft.com/Forums/en-US/85479b54-4cc8-4176-95f6-e27a80000e68/powershell-4-transcription-broken?forum=winserverpowershell

April 28th, 2015 3:03pm

Costly for anyone who has already used their own output formatters and -nonewline for example, write-output and the loss of control over formatting for scripts which are run by non technical people. Script output often needs to be brief in places - reworking would cost us all a lot, and really feels like a feature that would be in the shell implementation it-self. It's a script porting and diagnostics gap at the moment for me.

Are there and commercial shell hosts available that do this handling correctly and efficiently?

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 6:41am

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

Other recent topics Other recent topics