Bulk Cancellation of Power Automate Flow Runs

 Hello,

What if you saw 15.000 items in Power Automate history in "Running" state and there was a notification bar writing performance degradation and also Azure reports clearly identified massive requests due to ineffective nesting loops in a cloud flow and long delays in sub-flow calls .


Are you going to delete all one by one? No way :) 

I generated below PowerShell commands in order to cancel all runs in a supported way that saved my life. thus generated .ps1 file that contains necessary commands to help me.

It takes 2 parameters;

  • Environment Unique Id
  • Cloud Flow Unique Id to be cancelled of all suspended runs. 
Note : As you will guess it, Your account should have necessary privilege for the environment and also you should be owner of the Cloud flow. You can set ownership of cloud flow yourself temporary through make.powerapps.com


Command details;

First of all, We install PowerShell module of PowerApps and Administrator library then login to the environment with your account after that we fetch all runs of the selected cloud flows finally go through each item to cancel lonely "Running" state items.

we also keep log of cancellation operations in a file.


Here are the PowerShell commands of my work;


CancellingCloudFlowRuns_Get-FlowRun.ps1


*************************************************************************
$flowEnvironment=$args[0]
$flowGUID=$args[1]

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber
 
$pass = ConvertTo-SecureString "password" -AsPlainText -Force
Add-PowerAppsAccount -Username "UserName@domainname.onmicrosoft.com" -Password $pass

     
$runs = Get-FlowRun -EnvironmentName $flowEnvironment -FlowName $flowGUID 

       
foreach ($run in $runs) {
        if($run.status -eq "Running")
    { 
    Write-Output "Run details: " $run

    Write-Output "Run details: " $run | Out-File -FilePath C:\Logs\LogFileName.txt –Append

    # Cancel all the running flow runs
    m365 flow run cancel --environment $flowEnvironment --flow $flowGUID --name $run.FlowRunName --confirm

    Write-Output "Run Cancelled successfully"

    Write-Output "Run Cancelled successfully" | Out-File -FilePath C:\Logs\LogFileName.txt –Append
        }
}



*************************************************************************


Good Luck.

Comments

Popular posts from this blog

Exception caught instantiating TERADATA report server extension SQL Reporting Services

Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified at Configuration class initiation in CrmServiceHelper.cv

Dynamics CRM 365 Solution Template for Visual Studio 2019 Community Edition