I have a Microsoft Power Automate Flow that is triggered by a webhook – and for “reasons” it received thousands of triggers that I didn’t want:

Thousands of Flows that are about to do something that I don’t want….
Thousands.
Luckily time is on my side – Power Automate will only let a few Flows run concurrently so the majority of “running” Flows are actually queued and pending at the trigger stage – they’ve not done anything yet.
There is time for me to prevent carnage!
Cancel them!
Yes, you can cancel running Flows – but not in bulk – you can only do 20 at a time.

Turn it off? Delete it?
Nope – neither will work.
Turning off the Flow leaves all “running” Flows to finish.
Across the interwebs I’ve seen many recommendations of “export, delete , and re-import – the delete will stop them”.
Attempt that and Power Automate clearly says that things will continue to run:

Revoke credentials, block access?
Of course! If the thing is about to do something I don’t want – just stop it from being able to!
This works to an extent – many Flows subsequently failed to complete – but some were still being successful.
I don’t know if they’d already run but hadn’t reported that yet, or if they were using cached credentials – either way things were still happening that I didn’t want.
I just want to stop them all!
More trawling of the forums!
In my serach for a fix I did find https://mspower.herokuapp.com/ – this online tool offers the ability to bulk cancel – once you’ve hooked it into your Office 365 instance.
This does work – but there’s a timeout (on Microsoft’s end I suspect) that kills it after an hour or two:
An error occur: {'code': 'ExpiredAuthenticationToken', 'message': "The access token expiry UTC time '8/18/2022 9:01:20 AM' is earlier than current UTC time '8/18/2022 9:02:20 AM'."}
Much easier than doing it manually in batches of 20, but still far too much babysitting – and there’s little in the way of feedback as it goes which is unsettling.
Is this the fix?
Eventually I found this blog post: https://ashiqf.com/2021/05/16/cancel-all-your-running-power-automate-flow-runs-using-m365-cli-and-rest-api/.
Very promising – a bit of Powershell to iterate through all running instances and cancel.
However, the pre-requisites are painful for a Windows admin if you don’t have them set up already.
Maybe I should learn Linux someday…. 😉
The script uses Microsoft 365 CLI https://pnp.github.io/cli-microsoft365/… …which needs NPM…
…which needs Node.js…
To install NPM in Windows you need to follow https://docs.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-windows…
…which requires installing a Node Version Manager (https://github.com/coreybutler/nvm-windows#installation–upgrades).
Then (and only then) you can connect M365 CLI to your instance and run the script, for it to iterate through and cancel things:

Even if this does timeout after a while – at least I’m getting active feedback and can see what’s happening.
“No-code/low-code” should be easier
Don’t get me wrong – I love Power Automate and think it’s a fantastic way to achieve things that wouldn’t be feasible otherwise – and I do get that it’s a (relatively) new service that is being actively developed.
But – it’s unfortunate that there are some pitfalls that rely on the fantastic work of the community to resolve, and make “no-code/low-code” more “low-code until you exceed the functionality available, then you need to bust out the big guns and get all scripty and API calls”.
Leave a comment