- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- Jonas Andersson Mike Pfeiffer
- 361字
- 2021-07-16 13:26:36
Logging shell sessions to a transcript
You may find it useful at times to record the output of your shell sessions in a log file. This can help you save the history of all the commands you've executed and determine the success or failure of automated scripts. In this recipe, you'll learn how to create a PowerShell transcript.
How to do it...
To create a transcript, perform the following steps:
- Execute the
Start-Transcript
cmdlet:Start-Transcript c:\logfile.txt
- You can stop recording the session using the
Stop-Transcript
cmdlet:Stop-Transcript
How it works...
When starting a PowerShell transcript, you can specify a path and a filename that will be used to record your commands and their output. The use of the -Path
parameter is optional; if you do not provide a file path, the cmdlet will create a transcript file with a random name in the default documents folder in your profile path, as shown in the following screenshot:
When you are done, you can run the Stop-Transcript
cmdlet or simply exit the shell. You can use the -Append
parameter with the Start-Transcript
cmdlet to add a new transcript to an existing log file. When doing so, you'll need to specify the name of the file you want to append to using the -Path
parameter.
You can record your entire session every time you start the Exchange Management Shell by adding the Start-Transcript
cmdlet to your user profile. If you choose to do this, make sure you that specify the same log file to use every time the shell starts and use the -Append
parameter, so that each session is added to the log file every time.
There's more...
By default, only the output from PowerShell cmdlets will be recorded in your transcript. If you execute an external program, such as the Exchange eseutil.exe
utility, the output from this command will not be saved in your transcript file, even though it was run within the current shell session. You can pipe external programs to the Out-Default
cmdlet and this will force the output to be stored in your transcript.
See also
- Exporting reports to text and CSV files
- Automating tasks with the scripting agent
- Apache ZooKeeper Essentials
- Linux網(wǎng)絡(luò)程序設(shè)計(jì):基于龍芯平臺(tái)
- 高級(jí)C/C++編譯技術(shù)(典藏版)
- Reactive Programming With Java 9
- Mastering macOS Programming
- Android Wear Projects
- C# and .NET Core Test Driven Development
- Building Dynamics CRM 2015 Dashboards with Power BI
- Access數(shù)據(jù)庫(kù)應(yīng)用教程(2010版)
- C語言程序設(shè)計(jì)教程
- 一步一步學(xué)Spring Boot:微服務(wù)項(xiàng)目實(shí)戰(zhàn)(第2版)
- React.js實(shí)戰(zhàn)
- 邊做邊學(xué)深度強(qiáng)化學(xué)習(xí):PyTorch程序設(shè)計(jì)實(shí)踐
- 算法學(xué)習(xí)與應(yīng)用從入門到精通
- 零基礎(chǔ)輕松學(xué)Java