suppose I have the following code, when the error happens, I’d like to see the error that the error first happened at function b, and then happened at function a. But in fact it only tells me the error happen at function a, since function a could be called many times, I don’t know which outer function calling function a caused the problem
cls
function a{
Remove-Item "not-exist-item"
}
function b{
a
}
b
Remove-Item : Cannot find path 'C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\not-exis t-item' because it does not exist. At C:\Users\Daniel.Wu\AppData\Local\Temp\2\a.ps1:***3 char:14*** + Remove-Item <<<< "not-exist-item" + CategoryInfo : ObjectNotFound: (C:\Program File...\not-exist-item:String) [Remove-Item], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
If you are on PowerShell v2.0, use
Get-PSCallStack. If you’re still on v1, use a function like this: