- I have a script "B" from which I want to capture the debug
output of
Set-PSDebug -Trace nto a file. (File is the keyword here.) - I need to initiate the execution and debug capture 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 correct debug output of this is:
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 output is oddly just this:
DEBUG: 15+ >>>> FuncA
DEBUG: 6+ Function FuncA >>>> {
DEBUG: 7+ >>>> Write-Host "ABC"
ABC
123
123
The debugging messages stop after the first function, although the script finishes correctly.
Any ideas why and how to circumvent or avoid this?
Alternatively, I am looking for another solution to reach the two goals stated at the top.
BTW: I also tried using trace-command, which has a filepath parameter, but I don't know how to trace a whole script, and I do not know how to get the information Set-PSDebug provides: the lines being executed and the commands being executed, without all the rest.
I want to automatically process the debug output, and the output of Set-PSDebug is exactly what I need.
$PSVersionTablevariable)?.\b.ps1?Set-PSDebugusesWrite-Host. PowerShell 5.0 changed the wayWrite-Hostworks (it now writes to the Information Stream, aka stream 6). However, even running your example with PowerShell 2.0 still didn't recreate the bug on my end. Sorry.