How to Create Log File using Start-Transcript cmdlet in PowerShell
What is Start-Transcript?
As per MSDN, The Start-Transcript cmdlet creates a record of all or part of a PowerShell session to a text file. The transcript includes all commands that the user types and all output that appears on the console. Starting in Windows PowerShell 5.0, Start-Transcript includes the hostname in the generated filename of all transcripts.
When & Where to use?
As system admin/DevOps, we are doing much automation inside the servers and it’s mandatory to capture all the details (maybe error or success ran) in the log to make an analysis if required. In simple, if you running PowerShell scripts automatically you need a way to log any errors or warnings that occur. Usually, we will create your own log function (the same I did for my previous automation, please refer to my implemented method), but there is an easier way which I found during my team discussion and thought to share with all of you. This is especially useful when your enterprise’s logging is centralized.
The Start-Transcript cmdlet writes everything that happens during a session to a log file. These are the commands that you enter in a PowerShell session and all output that normally appears in the console.
You can also refer : Try/Catch , Error Handling , Error Logging
Source: https://dotnet-helpers.com/powershell/how-to-create-log-file-using-start-transcript-cmdlet-in-powershell/
Comments
Post a Comment
We appreciate your valuable feedback and comments