Canceling Jobs if there is a "loop"

Hi, I had a script that loops through a list and for each object it would prompt for a “response” because I made an error in the script…

If I cancel this job in the job history list, it only cancels the one task running, so if you have a list of several objects it would loop through, you have to press cancel for as many as your loop contains, before the job is really canceled.

Any other way to “really” cancel the job? not just the current task?

Apart from making errors :slight_smile:

Can you share a little code? A re you prompting with Read-Host?

This sounds like a bug but I want to make sure I reproduce it correctly.

No, I had a task running to connect to a customer environment and generate an Orca report (O365 analyzer) and since I failed to do the -connect $false on this command, it tries to connect with ExchangeOnline module that requires MFA (I connect in a different way, using secure app), so that prompted me to a “response” with the MFA, not a Read-Host.

So if I cancel that it cancels the response request, and then moves on to the next in the “foreach”, so I have to press cancel many times before it is really canceled.

Ok. Thanks. I’ll try and reproduce and let you know if I need any more info.

1 Like