Powershell $Error object not immediately populating inside PSM1 module

和自甴很熟 提交于 2019-12-05 04:10:23

I hadn't noticed that before, but perhaps the $error collection is scoped to the module like any other variables. Try comparing the values of the following two explicitly scoped variables at key points in your test script:

"Errors - Global: {0}; Module: {1}" -f $global:error.count, $script:error.count

Let me know how you get on.

As Ethan mentioned, you need to look at $global:error to see all of the errors. Modules always have they're own $error variable but it's (mostly) not used.

background: at one point, we had considered isolating errors that occurred in module code to the module scope but ultimately decided to add all errors to the global error collection since it is essentially a log of errors (like an in-memory eventlog.) Unfortunately the module scoped $error wasn't removed before the release and so you need to use the global scope qualifier to access the "real" $error variable.

Bruce Payette, Microsoft Corporation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!