Bulk cancel Azure Logic App runs with PowerShell

Bulk cancel Azure Logic App runs with PowerShell

Recently, I created an Azure logic app that sends different kinds of adaptive card messages to people via Teams. Then, it waits for the user to provide input via those adaptive cards before the execution continues beyond that point. As I was testing the logic app (by sending the cards to myself), I started a bunch of runs to test all the different scenarios and verify that the cards sent to Teams by the logic app looked as expected. By the end of my testing session, I had a bunch of active logic app runs waiting for me to take action. However, instead of providing input for all of my tests so the runs would end, I wanted to cancel the runs. Even though Azure Portal allows you to multi-select logic app runs, it only offers you an option to resubmit the runs, not cancel them. 🙁

Cancel Logic App runs with PowerShell

I could have opened the runs individually to cancel them, but as I had over 100 runs in progress, that didn’t seem like a very alluring idea. Instead, I started Visual Studio Code and whipped up the following PowerShell script to cancel the runs.

In addition to filtering the logic app runs by the status Running, I also wanted to filter them based on when they had been started. After my testing session, I had triggered some runs for pilot users, and I wanted to keep those going.

To utilize the script below, make sure you have PowerShell 7 installed. Then install or update the Az module via PowerShell 7 (run as administrator) using the Install-Module or Update-Module command. For more detailed installation instructions, see the Microsoft documentation.

Before you run the script, update the tenantId, subscriptionId, resourceGroupName, logicAppName, startTimeFrom, and startTimeTo variable values to match your environment and requirements. The script will display a list of the logic app run start times and prompt you for confirmation before stopping the runs so you can double-check that you are not canceling any runs you do not want to.

I hope you find the script useful and that you will never have to manually cancel a large number of individual logic app runs again. Happy developing, and until next time!

Laura



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.