PowerShell How-To

How To Use PowerShell Transcripts

Here's how to easily record every move made in PowerShell.

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.

[Click on image for larger view.]  Figure 1.

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.

[Click on image for larger view.]  Figure 2.

That's all there is to creating a transcript. Once created, it will then record everything you type and everything that's returned.

[Click on image for larger view.]  Figure 3.

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.

[Click on image for larger view.]  Figure 4.

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.

About the Author

Adam Bertram is a 20-year veteran of IT. He's an automation engineer, blogger, consultant, freelance writer, Pluralsight course author and content marketing advisor to multiple technology companies. Adam also founded the popular TechSnips e-learning platform. He mainly focuses on DevOps, system management and automation technologies, as well as various cloud platforms mostly in the Microsoft space. He is a Microsoft Cloud and Datacenter Management MVP who absorbs knowledge from the IT field and explains it in an easy-to-understand fashion. Catch up on Adam's articles at adamtheautomator.com, connect on LinkedIn or follow him on Twitter at @adbertram or the TechSnips Twitter account @techsnips_io.


comments powered by Disqus

SharePoint Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.