I am repeating a sample found within the CLI for Microsoft 365 examples which was insanely helpful for me.
I created a bulk update of about 2000 items within a SharePoint list – each one triggered a flow and with 2000 flows running at the same time, they started to time out, fail and just not complete – I needed to cancel all of them and start again
I found the code block on the M365 CLI site as i listed above.
You need the following
Install the M365 CLI in windows
npm i -g @pnp/cli-microsoft365
Log into m365 through a browser using
m365 login

Then run the following
$flowEnvironment = 'YourEnvironmentId'
$flowGUID = 'TheFlowGUID'
$flowRuns = m365 flow run list --environment $flowEnvironment --flow $flowGUID --output json | ConvertFrom-Json
foreach ($run in $flowRuns) {
if ($run.status -eq "Running") {
Write-Output "Run details: " $run
# Cancel all the running flow runs
m365 flow run cancel --environment $flowEnvironment --flow $flowGUID --name $run.name --confirm
Write-Output "Run Cancelled successfully"
}
}
The Environment and flow GUID can be found within the URL of your flow
Within the flow manage, open your flow – the references we are looking for are in the URL
The environment = ‘Default-8a47f942-xxxx-yyyy-a2c7-ced012b09a0a’
The flow GUID = ‘f0d07662-9ab2-bbbb-aaaa-dd11f2f47a47’

The flow runs and the flow is cancelled.
