I am trying to get the line number of the error when running a power shell script what am I currently using :
$ e = $ _ Exceptions $ line = $ _. exception. FrequencyInfo.Script LineNumber $ msg = $ e Write message-host - foreground color red "Exception caught: $ E $ on line" Sometimes it works and sometimes it does not happen I'm thinking Am I doing something wrong or what can I do to make this work more consistent?
I found out what was the problem:
Instead: $ e = $ _. Exceptions $ line = $ _Application.Allocation Info.ScriptLineNumber $ msg = $ e.Message Kit Host- ForegroundColor Red "code> It should be:
$ e = $ _. Exceptions $ line = $ _. InvocationInfo.ScriptLineNumber $ msg = $ e.Message Write-Host - Authorization Color Red "Exception caught: $ e $ line"
No comments:
Post a Comment