I've been using set-psdebug to send debug output to the console. I'd like to improve that by adding a time/date stamp since the output is captured and this would help troubleshoot issues after the fact. Anyone doing this or know how to do this?
This scripts all use:
set-psdebug -trace 1
this causes the output to look like this:
Debug: 14+ >>>> $ToFolder = "${UnixUserid}@${UnixServer}:${UnixFile}"
the goal is to add the time/date stamp to the left hand side of the Debug
I think the built-in cmdlet Set-TraceSource
is the most frictionless way to accomplish what you're wanting. You'll want to play around with the values available for -Option. I did try instantiating my own TraceListeners with higher TraceLevels but couldn't figure out how to get them bound to the running powershell console.
Set-PSDebug -Trace 1
Set-TraceSource -Name "ParameterBinding" -Option ExecutionFlow -PSHost -ListenerOption "DateTime"
foreach ($i in 1..3) { $i }
Reference: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-tracesource?view=powershell-6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With