Script logging best practices

I’m working on building a script to do VM creation/install OS/add to domain/configure OS, and one of the requirements is that the process be logged in some standardized format (to be determined).

What are recommended best practices for logging the execution of such a script?


Is this script going to be executed on a server or in a PE? On a running server you can enable scriptblock logging, windows logs to event viewer and non windows can log to syslog server. Check the following links for more information on this.


If you’re needing the actual script to log you could log to a network share or syslog server. Below are some articles that can help with this as well.


Sam already pointed out start-transcript, which could be used for logging interactive or automated scripts. It provides lots of information about the host environment. You can also add the -IncludeInvocationHeader switch and get timestamps added to the log. Don’t forget Stop-Transcript


I hope this helps.