How to use a transcript in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

Transcript in Powershell is like a recording session. So whenever you start a transcript in PowerShell, it starts recording your commands and outputs and doesn't matter if there is any error output, it gets recorded too. To start the transcript, you need to run Start-Transcript command at the beginning, and then whatever you write, it will get recorded.

To start the recording, you need to write Start-Transcript command and have to give the path for the transcript as shown in the below example,

Example

Start-Transcript -Path C:\Temp\sessionrecord.txt

Once you enter the above command you will get the message as shown below.

Start-Transcript -Path .\Sessionrecording.txt

Output

PS E:\scripts\Powershell> Start-Transcript -Path .\Sessionrecording.txt
Transcript started, output file is .\Sessionrecording.txt

Below is the PowerShell session screen after starting the transcript.

Example

PS E:\scripts\Powershell> Get-Service | Select -First 2
Status Name DisplayName
------ ---- -----------
Stopped AarSvc_777b7 Agent Activation Runtime_777b7
Running AdobeARMservice Adobe Acrobat Update Service


PS E:\scripts\Powershell> wrongcommand wrongcommand : The term 'wrongcommand' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wrongcommand
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (wrongcommand:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

The above commands should get recorded in the transcript. Simultaneously you can check the transcript file that the commands and outputs are recorded parallelly.

To stop the transcript, you need to run the Stop-Transcript command.

Example

PS E:\scripts\Powershell> Stop-Transcript
Transcript stopped, output file is E:\scripts\Powershell\Sessionrecording.txt

We will now check our transcript file sessionrecording.txt stored at the current location.

**********************
Windows PowerShell transcript start
Start time: 20200711122407
Username: DESKTOP-9435KM9\admin
RunAs User: DESKTOP-9435KM9\admin
Configuration Name:
Machine: DESKTOP-9435KM9 (Microsoft Windows NT 10.0.18362.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 4520
PSVersion: 5.1.18362.752
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.18362.752
BuildVersion: 10.0.18362.752
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is .\Sessionrecording.txt
PS E:\scripts\Powershell> Get-Service | Select -First 2

Status Name DisplayName
------ ---- -----------
Stopped AarSvc_777b7 Agent Activation Runtime_777b7
Running AdobeARMservice Adobe Acrobat Update Service


PS E:\scripts\Powershell> wrongcommand
wrongcommand : The term 'wrongcommand' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wrongcommand
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (wrongcommand:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
wrongcommand : The term 'wrongcommand' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ wrongcommand
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (wrongcommand:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

PS E:\scripts\Powershell> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20200711124434
**********************

You can notice in the above output that the user who executed the commands, computer name, start time, and end time is also recorded.

raja
Published on 11-Nov-2020 16:06:12
Advertisements