powershell - $error variable not available in modules? -


I have a lot of interest in using the try..catch statement in power scripts (especially when Calling external programs / COM objects etc.), and then use the automatic $ error variable to deal with the error.

My problem is that I have found that when module, $ error variable no longer works. I think that there is something with it that you are actually running while calling a function within a module, but it is being provoked in some way. Why do anyone know here, or even better: the solution?

I have a workaround: to make any external calls using invoke-expression by using the -errorVariable parameter, but rather complex Is - and not always the right proof.

What would the $ _ variable within the call block do?

Comments