Runing such script:
1: function foo() 2: { 3: bar 4: } 5: 6: function bar() 7: { 8: throw \"test\" 9: } 10: 11: foo
I see
You can not get a stack trace from exceptions of the PowerShell code of scripts, only from .NET objects. To do that, you will need to get the Exception object like one of these:
$Error[0].Exception.StackTrace $Error[0].Exception.InnerException.StackTrace $Error[0].StackTrace