Logging What a Script Does

by Aug 8, 2014

All PowerShell versions

You probably know that in a PowerShell console (not the ISE editor), you can turn on logging:

PS> Start-Transcript

This will log all entered commands and all command results to a file. Unfortunately it is of limited use when you run a script, because you cannot see the actual script commands.

Here is a radical trick that also includes all commands that your script executed. Before you try this trick, be aware that this will increase the size of your log file and can slow down script execution, because in loops, each iteration of a loop would also be logged.

This is all you need to enable logging script commands:

PS> Set-PSDebug -Trace 1

Twitter This Tip! ReTweet this Tip!