Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 1.07 KB

File metadata and controls

29 lines (22 loc) · 1.07 KB
tags
cleanup
flows

Cancel all running flow runs for a flow in an environment

Author: Mohamed Ashiq Faleel

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

Microsoft 365 CLI cmdlets will help you to cancel all the running 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.

=== "PowerShell"

```powershell
$flowEnvironment = $args[0]
$flowGUID = $args[1]
$flowRuns = m365 flow run list --environmentName $flowEnvironment --flow $flowGUID --status Running --output json | ConvertFrom-Json
foreach ($run in $flowRuns) {
  Write-Output "Run details: " $run
  # Cancel all the running flow runs
  m365 flow run cancel --environmentName $flowEnvironment --flow $flowGUID --name $run.name --confirm
  Write-Output "Run Cancelled successfully"
}
```