WoodITWork.com

It's about time I let the world know what I was thinking...

Output Powershell console to a file using Transcript

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