Powershell Tip:Capturing Your Session Output

Continuing on my journey of quick Powershell tip blog posts, another option that you normally want with your script files is an easy way in which to capture your session information so that you can have a log of all of your commands and outputs. Luckily, Powershell makes this fairly easy for you with the Start-Transcript command. The command syntax is below:

Start-transcript  <FileName>

Stop-transcript

So you can take a look at the output I got from my previous post on using the Format function in Powershell.

**********************
Windows PowerShell Transcript Start
Start time: 20090811211507
Username  : PERPTECH\arie.jones 
Machine      : LPT-AJONES01 (Microsoft Windows NT 5.1.2600 Service Pack 3) 
**********************
Transcript started, output file is log.txt
PS C:\> [string]::Format("{0:C}",12.99)
$12.99
PS C:\> [string]::Format("{0:###-##-####}",111223333)
111-22-3333
PS C:\> [string]::Format("{0:(###)###-####}",3178675309)
(317)867-5309
PS C:\> stop-transcript
**********************
Windows PowerShell Transcript End
End time: 20090811211605
**********************

Unfortunately, it has been well documented that there are some shortfalls within the transcript process within this framework …,..to the extent that some recommendations have been to stop transcription before a statement that does not get logged( sorry no real way to figure that out without doing it) ..pipe it to append it to end of file…then restart. Kind of a big pain and I am sure that they will be working on a couple of fixes…So you will just have to try it out and see within your set of processes.

Cheers,

AJ