Repository navigation
Description
I'm making the following assumptions about how Start-Transcript is designed to work (can't tell from the documentation):
- Whatever streams are neither captured nor redirected are transcribed, and preference variables with respect to which
Write-*cmdlets should actually produce output are honored; another way of putting it: Whatever output displays in the console, across all streams, is also what should get transcribed.
Currently, Start-Transcript doesn't always work that way:
-
Even with
*>$nullapplied to a script that usesStart-Transcript, which should keep all streams out of the transcript, errors (stream 2) andWrite-Hostoutput (stream 6) are still transcribed.-
You can partially keep error output out of the transcript If you use
$ErrorActionPreference = 'SilentlyContinue': outside of a transcript that would silence all errors (non-terminating, statement-terminating, script-terminating - albeit the latter two against documented behavior), but in a transcript cmdlet-triggered statement-terminating errors are unexpectedly still transcribed. -
Errors that do get transcribed are transcribed twice by default.
-
Cmdlet-triggered statement-terminating errors are preceded by an extra line repeating the error message, with a prefix such as
>>TerminatingError(<command>): <message>
It is this line that shows in the transcript even with$ErrorActionPreference = 'SilentlyContinue'in effect. -
Unlike outside of a transcript, with
$ErrorActionPreferenceat its default,$Continue:- a cmdlet-triggered statement-terminating error acts like a script-terminating one.
- a script-terminating error prints neither to the console nor records the error in the transcript.
- the transcript is aborted in both cases, however.
-
-
Even though[Update: This appears to have been fixed, but I don't know where and when (the problem persists in Windows PowerShell)]Write-Informationoutput (stream 6) is by default not printed to the console$InformationActionis'SilentlyContinue'by default), it is still transcribed.
Steps to reproduce
Create script t.ps1 with the following content:
$null = Start-Transcript t.log
write-warning 'warn'
write-verbose 'verbose'
write-information 'info'
write-host 'host'
write-output 'data'
# Generate a non-terminating error
Write-Error 'error'
# Generate an expression-based statement-terminating error.
1/0
# Generate a cmdlet-based statement-terminating error.
Get-Item -NoSuchParam
$null = Stop-TranscriptThen run the following commands, one after the other:
A)
./t.ps1B)
./t.ps1 *>$nullC)
& { $ErrorActionPreference = 'SilentlyContinue'; ./t.ps1 }Expected behavior
Inspect output file t.log:
A)
Coloring aside, whatever printed to the console should appear in the transcript (sandwiched between a header and a footer).
B)
Except for the header and footer, the transcript should be empty (all streams were suppressed).
C)
No errors of any kind should be transcribed.
Actual behavior
A)
INFO: infoshows in the transcript, even though it doesn't show in the console (with$InformationPreferenceat its default value,SilentlyContinue).
As an aside: Non-suppressedWrite-Informationoutput in the console has noINFO:prefix , but does in the transcript (whereasWrite-Warning,Write-VerboseandWrite-Debugprint a prefix in both scenarios).
[Update: This appears to have been fixed, but I don't know where and when (the problem persists in Windows PowerShell)]
- All errors show twice in the transcript.
- The first instance of the cmdlet-triggered statement-terminating error is preceded by an extra line duplicating the regular error representation:
>> TerminatingError(Get-Item): "A parameter cannot be found that matches parameter name 'NoSuchParam'."
- The first instance of the cmdlet-triggered statement-terminating error is preceded by an extra line duplicating the regular error representation:
B)
-
host(Write-Hostoutput) still shows in the transcript. -
All errors still show in the transcript (now only once).
C)
While the non-terminating error and the expression-triggered error were successfully suppressed, the cmdlet-triggered terminating error still shows in the transcript, but only by the extra line:
PS>TerminatingError(Get-Item): "A parameter cannot be found that matches parameter name 'NoSuchParam'."
Environment data
PowerShell Core v6.0.0-beta.5 on macOS 10.12.6
PowerShell Core v6.0.0-beta.5 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.5 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.483 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Activity
nowakca commentedon Oct 27, 2018
I've found that if I get a 404 from an Invoke-WebRequest inside a Try/Catch handler (which catches the error and provides no output, squelching it), I don't see anything on screen (which is as it should be), but I do see a "TerminatingError(Invoke-WebRequest)" and response content in the Transcript (which should not be)
rkeithhill commentedon Apr 29, 2019
OK this is a bit evil IMO. Enabling transcription should not fundamentally change the behavior of the script. I ran into this last Friday and took me a while to figure out this transcription bug was biting me. Here's my simple repro on a Linux machine using GNU make. There are two files (put in the same dir). Here is my simplified
makefile:And here is my
test.ps1file - be sure tochmod +x ./test.ps1to make it executable:With the above settings, I can execute this script and it works as I expect it to:
Now set the
$Transcribevariable to1and re-run the script. Just enabling transcription causes the script to crash now (the error handling behavior has fundamentally changed):BTW this issue does not crop up on Windows - adding to its "evilness".
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.