I have a script module whose .psm1 file runs a command that will fail if a certain registry value is not present. I want to ignore this failure, so the .psm1 script runs the command as:
CommandThatMayFail -ea SilentlyContinue
This works just fine when I import the module in a PowerShell session. But one of the functions in this module starts some PS Jobs that also require the module to be imported. When I import the module in the job's InitializationScript the failures from CommandThatMayFail are not ignored and the job terminates. I tried wrapping CommandThatMayFail in a Try/Catch block, but that didn't help any.
I have avoided the problem by importing the module in the job's ScriptBlock instead of the InitializationScript. But I am still curious about what is going on here. Can anyone shed any light?