I use powershell a lot at work – I’m not a guru by any means and I often find it hard to remember the commands I have run in a session, either for future use or for documenting in my time sheet (which also acts as a point of reference for future helpdesk tickets).
When I started going through the Powershell in a month of lunches book (which I highly recommend or the Powershell v3 book) I decided to use the start-transcript commandlet to record all my powershell activities. This worked very well until I would scroll through several screens worth and then forget what file I had saved my transcript too. There was also the possibility of forgetting to transcript everything.
By using the powershell profile file I was able to enter the commands to automatically set the transcript to the current date. I was then able to modify the title of the powershell prompt to display the filename so I could always see where the file was saved with the added bonus of a variable being used if I ever needed to open the transcript
My next step was to include the time in the powershell prompt – this enables me to go back through the transcript and see how long it took to run the commands for my timesheet entries. Remembering back to the good old dos days, I remembered the prompt command. A quick bit of experimenting with the Date command I had the current time displayed at the beginning on the Powershell prompt. Note this is displayed after the previous command is run, so technically it’s not the exact current time, but the time that the prompt was displayed on the screen.
The final profile script can be copy/pasted into notepad by typing in
is as follows:-
$log="c:\temp\powershelllogs-" + $env.username + (get-date -uformat "%y%m%d-%H%M") + ".txt"
$host.ui.rawui.WindowTitle = $log
write-host ((Date -uformat %T).ToString() + "PS " +$(get-location) + ">") -nonewline
return " "
This ends up with a powershell prompt that looks like the following. Hope this brief posting inspires you to change your powershell prompt to be even more useful for you.
<a href="https://absoblogginlutely.net/wp/wp-content/uploads/2013/09/masonichelpinghands.org-Screenshot-9_28_2013-4_00_11-PM.png"><img class="aligncenter size-full wp-image-3287" alt="Powershell prompt with the filename in the title and current time in the prompt" src="https://absoblogginlutely.net/wp/wp-content/uploads/2013/09/masonichelpinghands.org-Screenshot-9_28_2013-4_00_11-PM.png" width="671" height="211" /></a>