Scripts running multiple times

I seem to be having an issue with scripts trying to re-run automatically. I have Onboarding / Offboarding scripts that have pages as front ends, I’ll submit the form and the parameters will pass to my script which runs successfully the first time round. It will spit out a couple of log files during the script and that’s how I’ve noticed the issue, the script will just keep re-running (failing) and creating these log files. I have no idea what’s causing it and I’m having to stop the Universal Server service to prevent it from continuing.

Some context, I am using a service account but am NOT using Run As credentials, my retry limit is set to 0, I am using the default environment which should be PS 5.1. I have gone through my script a few times and can’t see anything that could be causing this to happen. It does also happen across multiple scripts. This is an MSI install of PowerShell Universal.

Product: PowerShell Universal
Version: 2.9.2

Is it possible the page is kicking off the script more than once? Or do you close the page and this still happens?

Initially I thought it might be because I reset the form to allow it to run again, but you can only do this once and the script would continue to retry after that.

Closing the page unfortunately also doesn’t prevent it from re-running either, I can cancel the task from the scripts / jobs page but it takes a little time to cancel and will then still try to re-run after that too.

I will look at creating some dummy scripts today with page front ends that throw some errors and see if these also run multiple times.

I’ve just dumbed down our offboarding script to test this, it basically includes some connections to Microsoft services via certificate auth, and some logging.

I created a page which just has a form with two fields, name and email. I submitted this form and closed the page immediately, then went to the scripts page to view the job running. This ran the first time, threw a warning and then continued to retry as many as 5 times before I eventually stopped the service on the server. I tried to cancel the task but this didn’t seem to make a difference.

The ID of the job doesn’t change so it is just trying to rerun the same job rather than create a new one.

Interesting. This could be hangfire (the job execution library we use) retrying the job rather than PSU retrying it. You might be able to find some more information here: Hangfire - PowerShell Universal

If that’s happening, PSU is throwing some sort of unhandled exception during job execution. Can you share a log file?