Cancel all your approvals in Microsoft Flow using PowerShell

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.

 

 

Advertisements

2 thoughts on “Cancel all your approvals in Microsoft Flow using PowerShell

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

    tommy

    Like

Leave a Reply to Pieter Veenstra Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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