Cancel all your approvals in Microsoft Flow using PowerShell

Powershell and Flow

Cancel all your approvals in Microsoft Flow using PowerShell

By:

Date:

Have you ever been silly enough to develop a flow that creates a lot of approval actions in Microsoft Flow?  I have! Now you need an easy way to cancel them all in this post I’m going to go through the steps.

 

I’m going to use PowerApps PowerShell. If you haven’t used this before the you will have to install this first.

Installing PowerApps PowerShell

The following two lines of PowerShell will install the right PowerShell modules for you ( make sure that you run PowerShell as administrator) :

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber

Get the Environment

Get-FlowEnvironment

This will list all your environments. Now find the right EnvironmentName for your flow

Get all the approvals

Get-FlowApprovalRequest -EnvironmentName Default-3985c6b6-11d8-4c13-84a9-1847f555ae47

This will list all the approvals for your environment. If you need to filter by flows then you might need to go through some more steps.

Delete all the approvals in your environment

To delete all the requests you could now run the following script:

$Requests = Get-FlowApprovalRequest -EnvironmentName Default-3985c6b6-11d8-4c13-84a9-1847f555ae47

foreach($Request in $Requests) {

Deny-FlowApprovalRequest -EnvironmentName Default-3985c6b6-11d8-4c13-84a9-1847f555ae47 -Comments "Cancelled" -ApprovalId $Request.ApprovalId -ApprovalRequestId $Request.ApprovalRequestId
}

Note that this will delete all your requests.If you don’t want to delete all the requests then you might have to add some filters to the Get-FlowApprovalRequest lines.

 

 

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There’s a better way — and I can show you exactly what it looks like. I’m the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I’ve been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://staging.sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://staging.sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@staging.sharepains.com

8 responses to “Cancel all your approvals in Microsoft Flow using PowerShell”

  1. Tommy Pang Avatar
    Tommy Pang

    Pieter, this is awesome. Wondering if you have any idea to cancel a particular Flow Approval instance from PowerApps.

    tommy

    1. Pieter Veenstra Avatar

      Hi Tommy,

      I have been thinking about the same. The only option I have found is to use the Title of the approval request.

  2. Suny Abraham Avatar
    Suny Abraham

    Hello Pieter,

    I believe P1 license is required for the above Powershell cmdlets to work,
    Please correct me if I am missing anything.Thank You !

    1. Pieter Veenstra Avatar

      Hi Suny,

      You are almost right.

      P1 doesn’t exist anymore. You can now simply have premium. Premium licences come in a premium user licence or in a Flow based premium licence.

  3. harzicn Avatar
    harzicn

    Could someone help. This is very useful but I want to filter only approvals with the title ‘VSRA Approval 2’. I do not want to cancel all the other approvals in course. How can I filter on the Title property to get just these approval flows to be cancelled? Thank you.

    1. Pieter Veenstra Avatar

      You would have to filter

      Get-FlowApprovalRequest -EnvironmentName Default-3985c6b6-11d8-4c13-84a9-1847f555ae47

      so you could use the folllowing:

      Get-FlowApprovalRequest -EnvironmentName Default-3985c6a6-11d8-4c13-84a9-1847f555ae47 | Where { $_.Title -eq “VSRA Approval 2” }

  4. Lisa Pohlmeyer Avatar

    This is a great solution, and I want to delete them all. There a several that were all used for testing. The script prompts for an ApprovalID and an ApprovalRequestID: for each of them. Suggestion on how I mitigate that?

    1. Pieter Veenstra Avatar

      I would need to look into details, but you could probably delete them from the Dataverse databases. But I would try that first in trial environments.

Leave a Reply

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