Start-Transcript: Add -IncludeTimeStamp parameter by soroshsabz · Pull Request #28230 · PowerShell/PowerShell · GitHub
Skip to content

Start-Transcript: Add -IncludeTimeStamp parameter - #28230

Open
soroshsabz wants to merge 5 commits into
PowerShell:masterfrom
soroshsabz:feature/add-timestamp-to-transcript
Open

soroshsabz wants to merge 5 commits into
PowerShell:masterfrom
soroshsabz:feature/add-timestamp-to-transcript

Conversation

@soroshsabz

@soroshsabz soroshsabz commented Oct 19, 2026 •

Copy link
Copy Markdown

PR Summary

Add an opt-in -IncludeTimeStamp switch to Start-Transcript that prefixes each recorded line of command input and output with the time it was produced, so long-running or headless scripts can be reviewed chronologically without cross-referencing external logs.

Start-Transcript ./log.txt -IncludeTimeStamp
Write-Host "This is a test"
Start-Sleep -Seconds 180
Write-Host "The end"
Stop-Transcript

Get-Content log.txt
...
2026-10-19 11:04:52 This is a test
2026-10-19 11:07:52 The end

PR Context

Resolves #24135

Design notes:

  • The timestamp (yyyy-MM-dd HH:mm:ss, invariant culture, local time ?????? consistent with the rest of the transcript, which uses local time) is applied when output is queued to the transcript buffer rather than when it is flushed to disk, so it reflects the time the output was actually produced.
  • Multi-line entries (e.g. error records, native command output) have each non-empty line prefixed.
  • Echoed command lines (PS> ... / >> ...) are also prefixed.
  • The transcript header/footer and -IncludeInvocationHeader banners are left unchanged since they already embed timestamps.
  • The feature is opt-in; without the switch, transcript output is byte-identical to before. This keeps existing ingestion mechanisms (e.g. JEA transcript collectors) unaffected, as discussed in the issue.
  • Known limitation: timestamps reflect the time a line was recorded to the transcript. Standalone native command output on Windows is captured from the console screen buffer once the process exits (the console buffer does not track per-line write times), so all lines of such a command receive the command's completion time. Piping native command output into a PowerShell command (e.g. native.exe | Out-Host) streams it through transcription line by line, so each line gets an accurate timestamp; redirecting native output directly to a file (e.g. native.exe > out.txt) bypasses transcription entirely.

PR Checklist

Add an opt-in IncludeTimeStamp switch to Start-Transcript that
prefixes each transcribed line of command input and output with
the time it was recorded, formatted as 'yyyy-MM-dd HH:mm:ss'
using the invariant culture and local time.

The timestamp is applied when output is queued to the transcript
(in TranscriptionCommand/TranscribeResult via the new
TranscriptionOption.AddOutput helper), so it reflects the time
the output was produced rather than the time it was flushed to
disk. Multi-line entries have each non-empty line prefixed.
Transcript header/footer and IncludeInvocationHeader banners are
left unchanged since they already contain timestamps.

Without the switch, transcript output is byte-identical to
before.

Resolves PowerShell#24135
@soroshsabz
soroshsabz requested a review from a team as a code owner October 19, 2026 05:42
Copilot AI balanced review requested due to automatic review settings October 19, 2026 05:42
@azure-pipelines

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Screen-scraped Windows native output receives completion-time timestamps rather than individual line-production times.

1 open issue
What changed in this PR

Adds opt-in transcript timestamps to support chronological log review, addressing #24135.

Changes:

  • Exposes Start-Transcript -IncludeTimeStamp.
  • Prefixes non-empty command and output lines when queued, leaving headers unchanged.
  • Adds tests for timestamped output and default behavior.
File Description
test/​powershell/​Modules/​Microsoft.Powershell.Host/​Start-Transcript.Tests.ps1 Tests timestamp prefixes, multiline output, and default behavior.
src/​System.Management.Automation/​engine/​hostifaces/​MshHostUserInterface.cs Stores the option and timestamps queued transcript content.
src/​Microsoft.PowerShell.ConsoleHost/​host/​msh/​StartTranscriptCmdlet.cs Exposes and forwards the new switch.

Review effort: Balanced

Standalone native command output on Windows is screen-scraped from
the console buffer only after the process exits, so with
-IncludeTimeStamp every line of that block receives the completion
time of the command. The console buffer does not record per-line
write times, so per-line production times cannot be recovered for
this path without redirecting the native output, which would change
how the command renders to the console. Piped or redirected native
output already streams through transcription line by line and gets
accurate per-line timestamps.

Document this in the Start-Transcript parameter help and at the
screen-scrape transcription site, and add a regression test for
timestamped native command output (piped, so it does not depend on
a physical console being available in the test environment).
@soroshsabz
soroshsabz requested a balanced review from Copilot October 20, 2026 16:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The redirection guidance incorrectly promises transcript capture for output redirected to a file.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread src/Microsoft.PowerShell.ConsoleHost/host/msh/StartTranscriptCmdlet.cs Outdated
Redirecting native command output directly to a file (for example
'native.exe > out.txt') transfers the bytes straight to the file and
bypasses transcription entirely, so it must not be suggested as a way
to capture per-line output. Only piping the native output into a
PowerShell command (for example 'native.exe | Out-Host') streams it
through the pipeline, where each line is recorded and timestamped as
it is produced.

Fix the guidance in the IncludeTimeStamp parameter help, the
screen-scrape comment in NativeCommandProcessor, and the PR
description accordingly.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved blocking issues remain; timestamping is opt-in, with focused tests and documented limitations.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a timestamp to transcript

2 participants