Output Powershell console to a file using Transcript
September 22nd, 2010
Sometimes it’s the simple things that really make a difference.
Often when writing any script you have to decide whether to output stuff to the screen or to a file.
What if you need to do both?
Normally you create additional scripting lines or a function to output the response from a cmdlet to a log file which you can review later.
Well I stumbled by accident across a very simple way to avoid this…just use the cmdlets Start-Transcript and Stop-Transcript which will output anything written to the screen into a text file.
$TranscriptFile = "c:\myoutput.log" Start-Transcript -Path $TranscriptFile Write-Host "I'm Transcripting!" Connect-VIServer myvcserver Get-VM Disconnect-VIServer Stop-Transcript Invoke-Item $TranscriptFile
Oh, this is nice! I’ve been looking for this exact thing. Thanks for the post.