GitHub Icon Image

Cancel all running flow runs for a flow in an environment

Summary

Do you want to automate the cancellation of running Power Automate flow runs?

This script will cancel all running flow runs of a Power Automate flow created in an environment. Pass the Flow environment id and the flow guid as parameter while running the script.

  • CLI for Microsoft 365 with PowerShell

$flowEnvironment = $args[0]
$flowGUID = $args[1]
$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"
  }
}

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Source Credit

Sample first appeared on Cancel all running flow runs for a flow in an environment | CLI for Microsoft 365

Contributors

Author(s)
Mohamed Ashiq Faleel

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI