Working in enterprise environments always requires a confidential log for scripting actions implemented in productive stages and even for testing it could be a great advantage. PowerShell offers a great possibility to log every action executed by a script. The CMDlets Start-Transcript & Stop-Transcript will help you to achieve a successful logging script.
This will be just an example how you can easyly create a logging script. There are thousands of different ways to solve this. The Microsoft documentation can be found in the following link https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1
The following script will write a general log file to C:\temp\logging.log containing all relevant basis information about the script execution.
Start-Transcript -path "C:\temp\logging.log" -Force
your CODE here
Result Read more