none
Powershell 4: Start-Transcript does not log Write-Host RRS feed

  • Question

  • 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
    Wednesday, January 14, 2015 2:42 PM

Answers

  • 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/


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Marked as answer by Hallgeirl Wednesday, January 14, 2015 3:46 PM
    Wednesday, January 14, 2015 3:28 PM
    Moderator

All replies

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


    ¯\_(ツ)_/¯

    Wednesday, January 14, 2015 2:55 PM
    Moderator
  • 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
    **********************


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Wednesday, January 14, 2015 3:00 PM
    Moderator
  • 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
    **********************


    ¯\_(ツ)_/¯

    Wednesday, January 14, 2015 3:06 PM
    Moderator
  • 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 :(
    Wednesday, January 14, 2015 3:20 PM
  • I thought the whole purpose of transcript was to log everything that's going on? And it DID work previously :)
    Wednesday, January 14, 2015 3:21 PM
  • 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/


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Marked as answer by Hallgeirl Wednesday, January 14, 2015 3:46 PM
    Wednesday, January 14, 2015 3:28 PM
    Moderator
  • Thanks Mike.

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

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

    Wednesday, January 14, 2015 3:46 PM
  • Wednesday, January 14, 2015 3:47 PM
    Moderator
  • 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 ?

    Friday, January 16, 2015 9:16 AM
  • Hi,

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

    Brent

    • Proposed as answer by Jason Warren Friday, February 6, 2015 5:59 AM
    Friday, January 23, 2015 1:58 AM
  • Friday, January 23, 2015 3:20 AM
    Moderator
  • Any indication of when this update is expected to be made available to the public?

    Kind Regards, Henk Hofs | http://www.IThastobecool.com

    Tuesday, February 3, 2015 4:10 PM
  • Any update on this matter? It has been almost 2 months now...

    Kind Regards, Henk Hofs | http://www.IThastobecool.com

    Wednesday, March 25, 2015 11:23 AM
  • 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

    Monday, April 13, 2015 8:33 AM
  • 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


    Kind Regards, Henk Hofs | http://www.IThastobecool.com

    Tuesday, April 28, 2015 7:02 PM
  • 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!

    Monday, June 22, 2015 8:17 PM
  • 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?


    automation of testing the stuff dude

    Thursday, September 3, 2015 10:39 AM
  • A hotfix is available for this bug:

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

    Thursday, September 17, 2015 11:16 AM
  • A similar issue is happening on powersherll 5, Windows Server 2008 R2. When the write-host comes from a remote machine it dones't works:

    PS C:\Windows\system32> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.0.10586.117
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.10586.117
    CLRVersion                     4.0.30319.18063
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1

    Transcript:

    **********************
    Windows PowerShell transcript start
    Start time: 20160518113250
    Username: 
    RunAs User: 
    Machine: 
    Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    Process ID: 3304
    PSVersion: 5.0.10586.117
    PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0.10586.117
    BuildVersion: 10.0.10586.117
    CLRVersion: 4.0.30319.18063
    WSManStackVersion: 3.0
    PSRemotingProtocolVersion: 2.3
    SerializationVersion: 1.1.0.1
    **********************
    Transcript started, output file is C:\Users\\Documents\PowerShell_transcript.zQE3Xa3S.20160518113250.txt
    PS C:\Windows\system32> Invoke-Command -ComputerName remote.machine -ScriptBlock {Write-Host "Hello" -fore yellow}  -UseSSL
    PS C:\Windows\system32> Stop-Transcript
    **********************
    Windows PowerShell transcript end
    End time: 20160518113259
    **********************

    Console:

    PS C:\Windows\system32> Invoke-Command -ComputerName remote.machine -ScriptBlock {Write-Host "Hello" -fo
    re yellow} -UseSSL
    Hello
    PS C:\Windows\system32> Stop-Transcript
    Transcript stopped, output file is C:\Users\\Documents\PowerShell_transcript.zQE3Xa3S.201605181
    13250.txt
    PS C:\Windows\system32>

    Can somebody confirm this is a bug like last time, or not?

    Thanks

    Wednesday, May 18, 2016 4:38 PM
    • Proposed as answer by Maaxeru Monday, March 27, 2017 10:02 PM
    Tuesday, November 22, 2016 6:54 PM
  • Works on PowerShell 5

    $path = 'c:\2\ts.txt' 
    Start-Transcript -Path $path -Force -Confirm:$false
    Write-Output "Write-Output Transcription Test"
    Write-Host "Write-Host Transcription Test" -ForegroundColor Green
    Stop-Transcript 
    Write-Host -ForegroundColor Cyan $([System.IO.File]::ReadAllText($path) )
    Remove-Item -Path $path -Force -Confirm:$false
    Monday, August 21, 2017 6:51 AM
  • This does not work at all for me - no output.

    I am using Powershell 5.1 on Windows 7

    Start-Transcript -Path 'C:\temp\log.txt' -Force
       Write-Host "host"
       Write-Information "info"
       Write-Output "output"
       Write-Verbose "verbose"
    Stop-Transcript


    • Edited by Tim Odell Tuesday, November 28, 2017 11:45 PM
    Tuesday, November 28, 2017 11:42 PM
  • Works for the rest of use:

    PS D:\scripts> cat C:\temp\log.txt
    **********************
    Windows PowerShell transcript start
    Start time: 20171128192021
    Username: ALPHA\jvierra
    RunAs User: ALPHA\jvierra
    Configuration Name:
    Machine: ALPHA (Microsoft Windows NT 10.0.16299.0)
    Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.
    Process ID: 11852
    PSVersion: 5.1.16299.64
    PSEdition: Desktop
    PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.16299.64
    BuildVersion: 10.0.16299.64
    CLRVersion: 4.0.30319.42000
    WSManStackVersion: 3.0
    PSRemotingProtocolVersion: 2.3
    SerializationVersion: 1.1.0.1
    **********************
    Transcript started, output file is C:\temp\log.txt
    PS D:\scripts> Write-Host "host"
    host
    PS D:\scripts> Write-Information "info"
    INFO: info
    PS D:\scripts> Write-Output "output"
    output
    PS D:\scripts> Write-Verbose "verbose"
    PS D:\scripts> Stop-Transcript
    **********************
    Windows PowerShell transcript end
    End time: 20171128192022
    **********************
    PS D:\scripts>



    \_(ツ)_/


    • Edited by jrvModerator Wednesday, November 29, 2017 12:22 AM
    Wednesday, November 29, 2017 12:21 AM
    Moderator
  • That is awesome for you.  I get nothing. :(
    Wednesday, November 29, 2017 12:24 AM
  • Start-Transcript -Path C:\temp\log.txt -Force
    $VerbosePreference = 'Continue'
    Write-Host "host"
    Write-Information "info"
    Write-Output "output"
    Write-Verbose "verbose"
    Stop-Transcript
    cat C:\temp\log.txt

    Using the correct syntax may help.  Copy and paste at a CLI prompt.

    \_(ツ)_/

    Wednesday, November 29, 2017 12:32 AM
    Moderator
  • I never heard of that $VerbosePreference setting. I'll have to read up on that. This does work now. Thanks!
    Wednesday, November 29, 2017 12:37 AM