I have a module that I need a bunch of my scheduled scripts to use. The problem is the module relies on external services and it sometimes fails. If the module fails, I need the script to be stopped without continuing. I can write the module to verify if it failed or not but I don’t know how to make it stop the Job if it detects it failed.
If I use the ‘Exit’ command from inside the module it just exits the module and continues the script. Also I don’t want to use the Job -erroraction stop because I need the script to continue when errors occur. Its just the module failing that I need to stop the Job. I’m thinking my best bet is Stop-PSUJob but I don’t know how to find the current Job ID to stop.
I am also aware I could do a try catch in the script when importing the module but there are reasons that would not be ideal in this situation.
Product: PowerShell Universal Version: 4.1.1