Ying Li at myITforum.com

PowerShell & System Center

The Comlet to record a PowerShell session

Sometime when we write powershell scripts, we will need to test out a lot of lines in the interactive PowerShell session. Once we have the working “lines”, we want to copy them back to the script. You can use edit -select -copy as in DOS. But PowerShell has two builtin cmdlets to help us recording a PowerShell session.

Start-Transcript – creates a record of all or part of a Windows PowerShell session in a txt file. The transcript includes all command that the user types and all output that appears on the console.

Stop-Transcript – stops a transcript that was started by using the Start-Transcript cmdlet. Of course, you can also stop a stranscript by ending the session.

Here is a sample output file:

**********************
Windows PowerShell Transcript Start
Start time: 20070915230637
Username  : MAYFLOWER\Ying
Machine   : MAYFLOWER (Microsoft Windows NT 5.1.2600 Service Pack 2)
**********************
Transcript started, output file is C:\Documents and Settings\Ying\My Documents\
PowerShell_transcript.20070915230637.txt
PS C:\PS> Get-Process svc*

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName         
-------  ------    -----      ----- -----   ------     -- -----------         
    228       6     3712       2916    68     1.40    356 svchost             
     94       5     2316        644    37     0.56    448 svchost             
    662      15     3292       3376    47    17.76    808 svchost             
    232       7     3856       1424    48     0.69    996 svchost             
   1948      94    24368      14688   169    37.35   1512 svchost             
    133       3     3000        148    39     0.39   1836 svchost             
    156       4     3264       1060    45     1.91   2084 svchost             
    101      12     2112        180    43     1.15   2772 svchost             


PS C:\PS> stop-process

cmdlet stop-process at command pipeline position 1
Supply values for the following parameters:
Id[0]: PS C:\PS> Stop-Transcript
**********************
Windows PowerShell Transcript End
End time: 20070915230700
**********************

Is this cool or what?

 

Posted: Sep 15 2007, 11:30 PM by yli628 | with no comments
Filed under:

Comments

No Comments