How To Use PowerShell Transcripts
Here's how to easily record every move made in PowerShell.
- By Adam Bertram
Have you ever been out somewhere and had a conversation with someone and thought to yourself, "I really need to remember this?" You get home, scramble for a notepad and then jot down everything you could remember. If so, you probably forgot some important detail you really needed to know and you got frustrated. Well, I can't help you memorize that favorite recipe or whatever it is -- there's programs for that -- but what I can do is ensure you never forget what PowerShell told you!
When either in the PowerShell console or when executing scripts, there are times when you simply need to know what happened. You don't care about it being in any kind of format or structure. You just need to see what happened. This is what transcripts are for. Transcripts are a way for you to take a glimpse back in time to see exactly what happened with your scripts or even in the interactive console.
When enabled, a transcript saves everything that normally just gets written to the PowerShell console. It will save errors, verbose, warnings, just about everything that you can see with your own eyes at the console. It saves all of this information to a text file you specify at start time. This is great and all but why would you even care what you typed in two months ago or even 30 seconds ago? Let me give you an example.
I'm a consultant (it's true, I am!) and I work for lots of different clients. As a consultant, I like to provide my clients with a report of my activity on a regular basis. One client always wants me to provide a daily breakdown of everything I did that day. Since I spend most of the day in PowerShell, I used a transcript. Here's how I did it.
Transcripts are created by the Start-Transcript cmdlet. The Start-Transcript cmdlet only requires a single parameter; Path. The Path parameter tells PowerShell what text file you'd like to store information in.
When the transcript is created it will look something like this it will have a header at the top that shows some basic information about the machine, user and the time it was started.
That's all there is to creating a transcript. Once created, it will then record everything you type and everything that's returned.
You can see from the screenshot I was playing around with the console and notice how it caught everything that I could see. It's just like a picture of the console every time you run something.
In my position, I wanted my transcripts to be on all the time and I wanted to keep everything I typed in a single file. The downside of a transcript is that it will stop and won't start again once you close the console plus it will erase the file every time if restarted. To prevent this, I'd put this line in my PowerShell profile and used the -Append parameter. By doing so, this allowed me to ensure a transcript was started every time I launched my console window and didn't remove what I had already done. Then I could guarantee that I captured all of my PowerShell activity all the time.
When the week was up and I forgot what I did on a certain day I could go back into my transcript to act as a reminder for me. This worked well.
What if you don't want a transcript running 24/7? You can just as easily stop the transcript.
As you can see, transcripts are very easy to work with and require no maintenance. Simply start one up, go about your day and stop it when you need to. Rest assured that all your activity will be captured into a single text file.
Adam Bertram is an independent consultant, technical writer, trainer and presenter. Adam specializes in consulting and evangelizing all things IT automation mainly focused around Windows PowerShell. Adam is a Microsoft Windows PowerShell MVP, 2015 powershell.org PowerShell hero and has numerous Microsoft IT pro certifications. He is a writer, trainer and presenter and authors IT pro course content for Pluralsight. He is also a regular contributor to numerous print and online publications and presents at various user groups and conferences. You can find Adam at adamtheautomator.com or on Twitter at @adbertram.