6

From Start-Transcript:

The Start-Transcript cmdlet creates a record of all or part of a PowerShell session to a text file. The transcript includes all command that the user types and all output that appears on the console.

Code

cls
$global:scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
$global:scriptName = $global:scriptPathAndName.Replace(($global:scriptPath + "\"),"")
$global:scriptNameNoExt = $global:scriptName.Replace(".ps1","")

Start-Transcript -LiteralPath ($global:scriptPath + "\" + (get-date -f "yyyy-MM-dd_HH-mm-ss") + "_" + $global:scriptNameNoExt + ".log") 

foreach ($n in 1..3)
{
    write-host -NoNewline ("test line " + $n + " ")
}

write-host 

Stop-Transcript

Console output - appears as expected

Transcript started, output file is C:\temp\2019-02-06_07-13-43_test.log
test line 1 test line 2 test line 3 
Transcript stopped, output file is C:\temp\2019-02-06_07-13-43_test.log

Transcript content - where did the newlines come from?

**********************
Windows PowerShell transcript start
Start time: 20190206071343
Username: xxx
RunAs User: xxx
Machine: xxx
Host Application: xxx
Process ID: 10092
PSVersion: 5.1.14409.1018
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1018
BuildVersion: 10.0.14409.1018
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\temp\2019-02-06_07-13-43_test.log
test line 1
test line 2
test line 3

**********************
Windows PowerShell transcript end
End time: 20190206071343
**********************
VA systems engineer
  • 2,856
  • 2
  • 14
  • 38
  • 3
    Looks like a bug; I encourage you to report it at https://github.com/PowerShell/PowerShell/issues – mklement0 Feb 06 '19 at 14:26
  • 3
    Done - created [issue #8836](https://github.com/PowerShell/PowerShell/issues/8836) – VA systems engineer Feb 06 '19 at 15:10
  • If you are executing as SYSTEM on Windows then the line-breaks seem to be related to the width of SYSTEM's default console window. – nudl Oct 14 '19 at 18:08
  • 1
    There's a [blog post](https://devio.wordpress.com/2009/03/04/setting-powershell-window-width/) which explains why this is so broken and what you might do to avert it. – nudl Oct 14 '19 at 18:18

0 Answers0