Easy ways to capture PowerShell output: 1 Start-Transcript

Sebastian Rogers
2 min readFeb 22, 2024

TL;DR Don’t write directly to files in PowerShell, use Start-Transcript instead.

Its common when running scripts to need to provide output of what happened, especially when doing bulk operations or DEVOps. This can either be to prove that it happened or for diagnostics when things go wrong.

You could add to all your scripts logging that writes directly to a file but that’s not a good idea.

  • You have to add it to every command you write.
  • It won’t cover native PowerShell commands.
  • It won’t cover commands in other people’s modules.
  • You don’t need to because Start-Transcript exists.

This handy command in the Microsoft.PowerShell.Host module writes out the commands and their output to a text file. See Start-Transcript for full details. When your done use Stop-Transcript.

You can even set this up in your PowerShell Profile so its just on all the time. I do this with PRODUCTION cloud shells so that there are no questions about what was actually done.

Useful, and not so useful parameters,

  • IncludeInvocationHeader, adds a timestamp before each command
  • OutputDirectory, specify a folder for the transcript I prefer this to path.
  • Path, lets you specify exactly what the transcript is called but the default naming convention is pretty good and avoids name clashes.

Enjoy.

TL;CR Don’t write directly to files in PowerShell, use Start-Transcript instead.

--

--

Sebastian Rogers

Technical Director for Simple Innovations Ltd. First paid for code in 1980, but still has all his own hair.