Cancel a variety of Microsoft Power Automate flows

Today I was faced with the task of maintaining a quite complex flow with several wait conditions. Some of these conditions should be changed, the running flows should be canceled, the flow should be processed and restarted.

But at the current time there were already flows waiting. Many flows. Actually, a total of 170 of them. Of course, Microsoft does not offer a “Cancel all running flows” button, that would be way too easy. You sadly also can’t select several flows at once and cancel them. My hope is, that this feature will come soon.

You have the following options

In this paragraph I will show you the options you currently have in the Power Platform. I have now found the following options to be notable:

  1. Firstly Make a copy of the flow and delete the old one. This will cancel all running power automate flows. After you did this, you might need a new prod deployment if you carry the power automate flow with a solution. That was rather suboptimal for me.
  2. Click through all flows by hand and cancel them (you can’t even select several…) and risk that I have to do it again at a later time / for a new customer request… So thats another bad choice to do.
  3. Cancel the flows via Powershell / m365cli which would have been my favorite option, but without Global Admin you don’t get permission. If you are in my situation, this is the most convenient option. Enter the following code in PowerShell and you are there (adjust flowEnvironmentID and flowGUID of course) That should be everything you need at this point.

npm i -g @pnp/cli-microsoft365

m365 login

m365 flow run cancel –environment flowEnvironmentID –flow flowGUID –name flowRunID –confirm

4. The variant for which I have decided to do is plain frontend coding. I wrote myself a JQuery Javascript, which I simply ran in the development console of the browser. (Press F12 in the browser and then switch to “Console”).

First copy paste the following code snippet:

var jq = document.createElement(‘script’);

Press enter. If you see a error message, just paste it again and press enter again. You should not see another error message. After this, you can paste the following snippet without andjustments if you are running the German interface. If you run an EN interface you replace Abbrechen with Excecuted and Wird with sheduled

confirm = function () {return true;};
setInterval(function () {

What the code does now is; Once a flow instance is selected, it runs and just keeps pressing the cancel button. Note, the code only works in German UI, but can be adapted to any language by changing “Wird” and “Abbrechen”. The 5000 at the end means that it waits 5 seconds, here you can go down to 2 seconds if you have a fast connection. Short: A flow is aborted every 2 seconds.

Leave a comment