- I have a script "B" from which I want to capture the debug output of
Set-PSDebug -Trace n to a file. (File is the key word here.) - I need to initiate the execution and debugging of script " B " from another script called A.
Example:
script B :
Set-PSDebug -Trace 1 Function FuncA { Write-Host "ABC" FuncB } Function FuncB { Write-Host "123" } FuncA FuncB
The debug output is correct :
DEBUG: 15+ >>>> FuncA DEBUG: 6+ Function FuncA >>>> { DEBUG: 7+ >>>> Write-Host "ABC" ABC DEBUG: 8+ >>>> FuncB DEBUG: 11+ Function FuncB >>>> { DEBUG: 12+ >>>> Write-Host "123" 123 DEBUG: 13+ >>>> } DEBUG: 9+ >>>> } DEBUG: 16+ >>>> FuncB DEBUG: 11+ Function FuncB >>>> { DEBUG: 12+ >>>> Write-Host "123" 123 DEBUG: 13+ >>>> }
.
But when I try to run it now from script A via start-process to capture the output to a file:
$SParguments = "-NoProfile -file `"$stdTracefile`"" Start-Process 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -ArgumentList $SParguments -RedirectStandardOutput $stdTracelog
the conclusion has a strange meaning:
DEBUG: 15+ >>>> FuncA DEBUG: 6+ Function FuncA >>>> { DEBUG: 7+ >>>> Write-Host "ABC" ABC 123 123
Debugging messages stop after the first function, although the script ends correctly.
Any ideas why and how to get around or avoiding this?
As an alternative, I am looking for another solution to achieve the two goals listed at the top.
BTW: I also tried using trace-command , which has a filepath parameter, but I donβt know how to track the whole script , and I donβt know how to get the information. Set-PSDebug provides: executable lines and executable commands , without the rest . I want to automatically handle the debug output, and the Set-PSDebug output is exactly what I need.
debugging powershell trace
Rob
source share