Skip to content

Feature Request: Transcript customisation #9354

@ghost

Description

Summary of the new feature/enhancement

As a user I want to change the format of Powershell transcripts so that my existing tools can parse them with minimal effort.

See issues #8720 and #8402 for examples of requests for this type of functionality.

I'm happy to implement this myself, just looking for feedback on the proposed technical implementation first.

Proposed technical implementation details

Start-Transcript could accept an optional script block for each type of transcript segment: header, line and footer.

For example:

Start-Transcript
    -HeaderTemplate { "Custom header" }
    -LineTemplate { param($command, $result) "{input: '$command', output: '$result'}"}

    # -FooterTemplate is not specified, so falls back onto a script block defined
    # in environment var, or default implementation, as in this example.

This would produce the following transcript test.txt for a session of one command (write-host "test") with a prompt PS prompt>.

Custom header
{ input: '', output: 'Transcript started, output file is .\test.txt' }
{ input: 'PS prompt> write-host "test"', output: 'test' }
{ input: 'PS prompt> Stop-Transcript', output: '' }
**********************
PowerShell transcript end
End time: 20190414081054
**********************

I'm suggesting script blocks to allow maximum flexibility. Other cmdlets for specific formats could be built on top of this, e.g. Start-TranscriptJson, Start-TranscriptXml, Start-TranscriptMyCustomFormat.

Since Powershell outputs to different streams, the $result argument to the -LineTemplate script block should reflect the order of outputs and to which stream. For example, a data structure like List<Tuple<StreamType, String>> where StreamType is an enumeration of the output stream types (Success, Verbose, Error, Warning, Debug). This detail is omitted from the example for the sake of simplicity for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions