Using Start-Transcript in ISE Profile

This week on the Scripting Guys blog they have been doing some posts on PowerShell user profiles and the kinds of things people have in them and what they are for. This prompted me to finally do something I have been meaning to for a while: Add something to my ISE Profile that starts a transcript every time I open ISE.

Some time ago I stumbled upon this module that lets you run Start-Transcript in ISE. I have only used it sparingly however, because I always forget to turn it on. Not after today!

The format for Start-Transcript is pretty simple, all you need to have is a path to store the transcript file in.

Now, this is great and all, but when I open up my ISE Console tomorrow, or the next day, I don’t want it to just keep piling everything into the same text file. I wonder if I can just name the file with today’s date using the Get-DateTime cmdlet?

Well, that’s not real helpful. I spent about the next 10 minutes exploring all the various Methods and Properties of Get-Date, and wasn’t having any luck so I decided to go to the help file. It also just so happens that the last example is exactly what I am looking to do, so I included that as well.

I don’t like the format of that DateTime object, so I decided to investigate what other types of objects there were.

I searched for Format, which right in the help file gave me the link to the MSDN article explaining the different format options. Looking at all the different format patterns, I elected to just start at the type with pattern d, and go from there.

Well look at that! Exactly what I need, except for the /’s because I can’t use those in a filename. Referencing the example in the help file, I change my command to this.

Perfect! Now, let’s tie this all together.

I added the Append parameter because if I open close ISE throughout the day I want it to just keep adding on to the existing file and not overwrite the existing one every time I restart ISE during a given day.

All you need to do to add this to your profile is download the module linked at the beginning of the post, and then add these 3 lines to your profile (you can use notepad $profile from PowerShell to make it easy on yourself).