Start-Transcript in PowerShell: Log Everything in a Session

When a 2 AM account cleanup goes wrong, the first question is always “what did the script print?” Start-Transcript answers it: it writes everything the session shows on screen to a text file until you run Stop-Transcript.

Start-Transcript -Path 'C:\Logs\cleanup.txt'
# ... your commands ...
Stop-Transcript

In this tutorial, I’ll show you how Start-Transcript works in PowerShell 7 and Windows PowerShell 5.1: where the file goes, how to append or protect it, what it captures and misses, and how to log every session.

Quick answer: these are the forms you’ll use most:

GoalCommand
Log to a file you nameStart-Transcript -Path C:\Logs\run.txt
Let PowerShell name the fileStart-Transcript -OutputDirectory C:\Logs
Add to an existing logStart-Transcript -Path C:\Logs\run.txt -Append
Never overwrite a logStart-Transcript -Path C:\Logs\run.txt -NoClobber
Stop recordingStop-Transcript

How to start and stop a transcript in PowerShell

Start-Transcript takes the file path as its first parameter, so -Path is optional. Everything after it, including Write-Host lines, lands in the file until Stop-Transcript. Here’s a small account cleanup that logs itself:

$log = 'C:\psfaqs\Transcripts\account-cleanup.txt'
Start-Transcript -Path $log
'Checking 3 accounts for the Denver office...'
Write-Host 'Disabled: Tom Baker'
Stop-Transcript
Get-Content -Path $log | Select-String -Pattern 'Denver|Disabled'

Output:

Transcript started, output file is C:\psfaqs\Transcripts\account-cleanup.txt
Checking 3 accounts for the Denver office...
Disabled: Tom Baker
Transcript stopped, output file is C:\psfaqs\Transcripts\account-cleanup.txt

Checking 3 accounts for the Denver office...
Disabled: Tom Baker

Both cmdlets print the file path. The last two lines come from the file, so the Write-Host message was recorded too.

The folder didn’t exist before this run. Microsoft’s docs say -Path fails when a folder is missing, but in my tests PowerShell 7.6 and 5.1 both created it.

A transcript records the whole console. When you only want chosen lines in a log, write your own log file with Add-Content instead.

What does a PowerShell transcript file contain?

Each transcript has a header block between rows of asterisks, the session output, and an end block. I filtered the header to the lines that differ between versions:

$log = 'C:\psfaqs\Transcripts\header.txt'
Start-Transcript -Path $log | Out-Null
Stop-Transcript | Out-Null
$keep = 'transcript start$|^(Username|Machine|PSVersion|PSEdition|OS|BuildVersion):'
Get-Content -Path $log -TotalCount 20 | Where-Object { $_ -match $keep }

Output:

PowerShell transcript start
Username: DESKTOP-4T7K2QX\alice
Machine: DESKTOP-4T7K2QX (Microsoft Windows NT 10.0.26200.0)
PSVersion: 7.6.7
PSEdition: Core
OS: Microsoft Windows 10.0.26200

The output above is from PowerShell 7. Windows PowerShell 5.1 printed the same Username and Machine lines, but it starts with “Windows PowerShell transcript start”, shows PSVersion 5.1 and PSEdition Desktop, and lists BuildVersion instead of OS.

I replaced my user and computer name with alice and DESKTOP-4T7K2QX. The PSVersion line shows which engine ran a job, the same value you get when you check your PowerShell version.

Shorten the header with -UseMinimalHeader (PowerShell 7)

PowerShell 6.2 added -UseMinimalHeader, which keeps only the start line and