Start-Transcript creates a record of PowerShell Sessions. For documenting and archiving. The feature is very useful for administrative tasks and programming. This article describes the use of Start-Transcript and Stop-Transcript on the localhost and in remote sessions.
Simply type start-transcript and your session will be recorded in your home folder. The created text file includes the date of recording and your hostname.
To specify another location and file name provide the path parameter.
Start-Transcript -Path c:\Temp\Log1.txt
Start-Transcript overwrites files without warning. A workaround is the NoClobber parameter.
Start-Transcript -NoClobber -Path C:\Temp\Log1.txt
The parameter Append adds the new transcript to the end of an existing file.
Start-Transcript -Append C:\Temp\Log1.txt
After quitting PowerShell, the recording stops. You can stop recording manually by running Stop-Transcript.
Start-Transcript on Remote Hosts
In a PowerShell remote session, you can start recording on the remote host. The file is saved on the remote computer. I am logged on Server03. I start a PowerShell Session to DC01 and run Start-Transcript. Look what happens:
Enter-PSSession -ComputerName dc01 Start-Transcript
For more information about PowerShell Remote Session see my article How to configure Trusted Hosts for PowerShell Remote Sessions.
What does the file look like?
Well, the file will not win a beauty award. But all important informations and commands of your PowerShell Sesssion are saved and documented.
To start recording every time when you start PowerShell, simply modify your PowerShell Profile. To create a profile type
New-Item -Path $Profile -Force
Next, add Start-Transcript to your profile.
Add-Content -Path $Profile -Value "Start-Transcript"
This will start recording automatically. Close PowerShell and open it again. You should see the following:
Include Start-Transcript in your PowerShell Profile: How to create PowerShell Profiles or configure logging for each module separately: Monitoring Windows PowerShell: Enable Module Logging