Nested PowerShell Transcripts

by Apr 8, 2016

In previous versions of PowerShell, session logging (transcripts) were supported only in the PowerShell console, and there could only be one transcript log active at a time.

In PowerShell 5.0, transcripts can be nested, and work in all hosts. Your script can easily start its own transcription in its own log file. Have a look:

 
PS> Start-Transcript
Transcript started, output file is C:\Users\Tobias\Documents\PowerShell_transcript.DELL1.BGiNcMzC.20160330075046
.txt

PS> Start-Transcript -Path C:\Temp\mylog.txt -Append
Transcript started, output file is C:\Temp\mylog.txt

PS> Stop-Transcript
Transcript stopped, output file is C:\Temp\mylog.txt

PS> Stop-Transcript
Transcript stopped, output file is C:\Users\Tobias\Documents\PowerShell_transcript.DELL1.BGiNcMzC.20160330075046
.txt
 

As you can see, each call to Start-Transcript starts a new transcript session, and each call to Stop-Transcript stops the topmost session. When you use the -Path and –Append parameters, you can directly log input and output to your own log files. Just make sure your script stops any transcript that it started.

Twitter This Tip! ReTweet this Tip!