Keeping a history of your console sessions

When I started with PowerShell just a couple of months ago I was trying out lots of things on the PowerShell console. And after trial and many errors I finally got the results that I wanted.
However, the following day I often found myself scratching my head wondering how I got those results a day before. So after some searches I discovered the Start-Transcript Cmdlet!

This Cmdlet keeps a transcript of my console session so all I had to do now is begin my session with Start-Transcript and a log file would automatically be created. If I didn’t forget to start my session with Start-Transcript, that is.
So after forgetting to start a transcript a couple of times I simply added it to my PowerShell profile, so I couldn’t forget anymore.

Then what bugged me is that my older transcripts got overwritten whenever I started a new transcript. So I added a datestamp to my transcripts. Which worked fine, until I noticed I ended up accumulating hundreds of log files.

So here is my solution for that. All this takes place in your PowerShell profile.
First, remove all accumulated log files which are older than, say, 7 days, and then start a new date-time stamped logfile. So even if I have multiple PowerShell consoles open at a time, each console gets its own logfile.



Tagged . Bookmark the permalink.

Comments are closed.